Ask Your Question

Revision history [back]

Netcat stream on /dev/stdin not working with OpenCV 3.1.0-dev on Ubuntu 16.04

Hello to everyone. I m encountered a "strange" problem trying to stream a video using netcat from my Raspberry Pi (using the Pi Camera).

The problem is the following: If I use Opencv 2.4.13, everything is okay, and I m able to see on my laptop the video coming from the Raspberry with an acceptable latency (~100ms) using simply:

ON RASPBERRY PI:    
raspivid -n -t 0 -w 800 -h 600 -fps 30 -o - | nc 145.94.195.184 5000

ON LAPTOP
nc -l -p 5000 | python testVideo.py

Reading from /dev/stdin using the function "VideoCapture"

cap = cv2.VideoCapture("/dev/stdin")

But If I want to use Opencv 3.1.0-dev (installed on another ubuntu 16.04 partition), nothing works. Obtaining the following error:

Unable to stop the stream: Inappropriate ioctl for device
GStreamer: Error opening bin: Unrecoverable syntax error while parsing pipeline /dev/stdin
      OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/vgarofano/opencv/modules/imgproc/src/color.cpp, line 9748
    Traceback (most recent call last):
      File "testVideo.py", line 22, in <module>
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.error: /home/vgarofano/opencv/modules/imgproc/src/color.cpp:9748: error: (-215) scn == 3 || scn == 4 in function cvtColor

The code I am using is a simple "read the video and show it":

import numpy as np
import cv2

cap = cv2.VideoCapture("/dev/stdin")

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

How it is possible that the same code works perfectly with OpenCV 2.4.13 while it gives errors using OpenCV 3.1.0-dev? I think that there is something different with the function VideoCapture, but I am not able to understand how to fix it. Someone that maybe already faced this type of problem could help me? I tried almost everything found on this forum, but nothing changed.

Remarks: I need to use the OpenCV 3.1.0-dev because with opencv_contrib package I want to use the Aruco library (already well imported in Python) to perform some applications detecting markers. Another constraint is that I need it using Python, because I am developing a GUI interface for a ROV using pygame (for other type of applications). By the way the final goal is to stream from the Raspberry camera, in a local network, with acceptable latency and the possibility to manage the video with OpenCV. So, if you have also some other suggestions on how implement it, could be also also very helpful.