Skip to content

Instantly share code, notes, and snippets.

@arjo129
Created February 7, 2018 08:07
Show Gist options
  • Save arjo129/d4871a91db98468593a6396e234387e2 to your computer and use it in GitHub Desktop.
Save arjo129/d4871a91db98468593a6396e234387e2 to your computer and use it in GitHub Desktop.
import rospy
from sensor_msgs.msg import *
from cv_bridge import CvBridge
import cv2
import numpy as np
bridge = CvBridge()
rospy.init_node("Redmasker")
image_pub = rospy.Publisher("RedMasked",Image)
def img_handler(msg):
img = bridge.imgmsg_to_cv2(msg,"bgr8")
dat = cv2.inRange(img, np.array([0,0,0]), np.array([100,100,255]))
img=cv2.bitwise_and(img,img,mask=dat)
image_pub.publish(bridge.cv2_to_imgmsg(img,"bgr8"))
sub = rospy.Subscriber("/Image_topic0",Image,img_handler)
rospy.spin()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment