Sending images from Python and Opencv

Example

import cv2
import numpy as np
import sys
import nep
import time

id_ = 0
x_resolution = 640
y_resolution = 480

node = nep.node('camera_python')
conf = node.direct("192.168.1.10", "8585", "one2many")
pub_image= node.new_pub("testImage", "image", conf)

video = cv2.VideoCapture(id_)

video.set(cv2.CAP_PROP_FRAME_WIDTH, x_resolution)
video.set(cv2.CAP_PROP_FRAME_HEIGHT, y_resolution)

print("camera service started")

while True:

    try:
        success, frame = video.read()
        if success:
            pub_image.publish(frame)

            cv2.imshow("python", frame)
            key = cv2.waitKey(1) & 0xFF
            if key == ord('q') or key == ord('Q') or key == 0x1b:
                break
        else:
            time.sleep(.001)

    except:
        
        video.release()
        cv2.destroyAllWindows()
      
        time.sleep(1)
        pass

Last updated