#!/usr/bin/env python

import roslib
import rospy
import cv2

import numpy as np
import sys
from std_msgs.msg import Header
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError

class image_components:
	def __init__(self):
		self.bridge=CvBridge()
		self.image_sub=rospy.Subscriber("bebop/image_raw",Image,self.callback)
	def callback(self, data):
		try:
			cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
		except CvBridgeError as e:
			print(e)
		
		b = cv_image.copy()
		# set green and red channels to 0
		b[:, :, 1] = 0
		b[:, :, 2] = 0

		g = cv_image.copy()
		# set blue and red channels to 0
		g[:, :, 0] = 0
		g[:, :, 2] = 0
	
		r = cv_image.copy()
		# set blue and green channels to 0
		r[:, :, 0] = 0
		r[:, :, 1] = 0
	
		# RGB - Blue
		cv2.imshow('B-RGB', b)
		#cv2.imwrite("Bleu2.png", b)
		# RGB - Green
		cv2.imshow('G-RGB', g)
		#cv2.imwrite("Vert2.png", g)
		# RGB - Red
		cv2.imshow('R-RGB', r)
		#cv2.imwrite("Rouge2.png",r)
		# RGB
		cv2.imshow("RGB", cv_image)
		#cv2.imwrite("couleur2.png", cv_image)
		cv2.waitKey(3)

def main(args):
	ic = image_components()
	rospy.init_node('image_components', anonymous=True)
	try:
		rospy.spin()
	except KeyboardInterrupt:
		print("Shutting down")
	cv2.destroyAllWindows()
 
if __name__ == '__main__':
     main(sys.argv)

