Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 600

Read a named pipe in opencv

$
0
0
Hi, I'm following this video guide (I'm using the last option presented in the video): https://www.youtube.com/watch?v=sYGdge3T30o Essentially my raspberry send a video stream with netcat, then a script on my pc receives this stream and redirects it in a pipe. I tried to access the pipe with this: VideoCapture cap("path to pipe"); it works, but requires minutes of waiting. Is there a way to drastically reduce this waiting time? Alternatively, I found a code (posted below) in openCV that works fine, but it's in python and I need it in C++ for my project. Is there a way to reach the same result in C++? Thank you everybody. import cv2 import subprocess as sp import numpy FFMPEG_BIN = "/home/gaspare/ffmpeg_sources/ffmpeg/ffmpeg" command = [ FFMPEG_BIN, '-i', 'fifo264', # fifo is the named pipe '-pix_fmt', 'bgr24', # opencv requires bgr24 pixel format. '-vcodec', 'rawvideo', '-an','-sn', # we want to disable audio processing (there is no audio) '-f', 'image2pipe', '-'] pipe = sp.Popen(command, stdout = sp.PIPE, bufsize=10**8) while True: # Capture frame-by-frame raw_image = pipe.stdout.read(1280*720*3) # transform the byte read into a numpy array image = numpy.fromstring(raw_image, dtype='uint8') image = image.reshape((720,1280,3)) # Notice how height is specified first and then width if image is not None: cv2.imshow('Video', image) if cv2.waitKey(1) & 0xFF == ord('q'): break pipe.stdout.flush() cv2.destroyAllWindows()

Viewing all articles
Browse latest Browse all 600

Trending Articles