NEP+ Docs
  • NEP+ middleware documentation
  • Developer Tools
    • NEP CLI
  • User interfaces
    • Install NEP+ App (Windows)
    • Install NEP+ App (macOS)
    • NEP+ App (0.0.4) - Deprecated
  • Concepts for developers
    • Message Format
    • Tutorials for developers
      • Connecting Multiple Scripts on the Same Computer using NEP+ Tools: A Step-by-Step Tutorial
      • Connecting 2 scripts in a local network (e.g., two computers on the same Wifi network)
      • Connecting ROS to non-ROS nodes using NEP+ tools
  • Programming enviroments
    • Python
    • C# (Unity)
    • C# (Visual Studio)
    • Javascript (Node.js)
    • Java/Kotlin (Android Studio)
    • Java (Netbeans)
    • C++ (Visual Studio)
  • Other tutorials
    • Pepper & NAO robots
      • Using Pepper without Pepper in Choregraphe
      • Install Pepper/NAO SDK
  • Code examples
    • Sending images from Python and Opencv
Powered by GitBook
On this page
  1. Code examples

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 1 year ago