Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Publish Image msg ros python

#!/usr/bin/env python

import rospy
from sensor_msgs.msg import Image

import cv2
from cv_bridge import CvBridge, CvBridgeError

rospy.init_node('VideoPublisher', anonymous=True)

VideoRaw = rospy.Publisher('VideoRaw', Image, queue_size=10)
NeedleBorder = rospy.Publisher('NeedleBorder', Image, queue_size=10)

cam = cv2.VideoCapture('output.avi')

while cam.isOpened():
    meta, frame = cam.read()

    frame_gaus = cv2.GaussianBlur(frame, gaussian_blur_ksize, gaussian_blur_sigmaX)

    frame_gray = cv2.cvtColor(frame_gaus, cv2.COLOR_BGR2GRAY)

    frame_edges = cv2.Canny(frame_gray, threshold1, threshold2)

    # I want to publish the Canny Edge Image and the original Image
    msg_frame = CvBridge().cv2_to_imgmsg(frame)
    msg_frame_edges = CvBridge().cv2_to_imgmsg(frame_edges)

    VideoRaw.publish(msg_frame, "RGB8")
    NeedleBorder.publish(msg_frame_edges, "mono8")

    time.sleep(0.1)
Comment

PREVIOUS NEXT
Code Example
Python :: convert all numbers in list to string python 
Python :: Selecting subset of columns with pandas 
Python :: selenium python find element by class name with space 
Python :: win64pyinstaller 
Python :: how to download from url in python 
Python :: arithmetic in python 
Python :: how to host python flask web application 
Python :: how to remove some characters from a string in python 
Python :: delete last message discord.py 
Python :: jupyter change cell to text 
Python :: to_cvs python 
Python :: flask docs 
Python :: transformers bert 
Python :: python for loop with index 
Python :: train dev test split sklearn 
Python :: python set timezone windows 
Python :: check for string in list py 
Python :: how to make a random int in python 
Python :: create a date list in postgresql 
Python :: renpy 
Python :: flask bootstrap 
Python :: how to define functions in python 
Python :: python stack data structure 
Python :: power of array 
Python :: how to get mac address in python 
Python :: Swap first and last list elements 
Python :: highlight null/nan values in pandas table 
Python :: how to delete item from list python 
Python :: python override string class 
Python :: delete all messages discord.py 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =