OpenCV Python, reading video from named pipe -


i trying achieve results shown on video (method 3 using netcat) https://www.youtube.com/watch?v=sygdge3t30o

the point stream video raspberry pi ubuntu pc , process using opencv , python.

i use command

raspivid -vf -n -w 640 -h 480 -o - -t 0 -b 2000000 | nc 192.168.0.20 5777

to stream video pc , on pc created name pipe 'fifo' , redirected output

 nc -l -p 5777 -v > fifo 

then trying read pipe , display result in python script

import cv2 import sys  video_capture = cv2.videocapture(r'fifo') video_capture.set(cv2.cap_prop_frame_width, 640); video_capture.set(cv2.cap_prop_frame_height, 480);  while true:     # capture frame-by-frame     ret, frame = video_capture.read()     if ret == false:         pass      cv2.imshow('video', frame)      if cv2.waitkey(1) & 0xff == ord('q'):         break  # when done, release capture video_capture.release() cv2.destroyallwindows() 

however end error

[mp3 @ 0x18b2940] header missing error produced command video_capture = cv2.videocapture(r'fifo')

when redirect output of netcat on pc file , reads in python video works, speed 10 times approximately.

i know problem python script, because nc transmission works (to file) unable find clues.

how can achieve results shown on provided video (method 3) ?

i wanted achieve same result in video. tried similar approach yours, seems cv2.videocapture() fails read named pipes, more pre-processing required.

ffmpeg way go ! can install , compile ffmpeg following instructions given in link: https://trac.ffmpeg.org/wiki/compilationguide/ubuntu

once installed, can change code so:

import cv2 import subprocess sp import numpy  ffmpeg_bin = "ffmpeg" command = [ ffmpeg_bin,         '-i', 'fifo',             # fifo named pipe         '-pix_fmt', 'bgr24',      # opencv requires bgr24 pixel format.         '-vcodec', 'rawvideo',         '-an','-sn',              # want disable audio processing (there 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(640*480*3)     # transform byte read numpy array     image =  numpy.fromstring(raw_image, dtype='uint8')     image = image.reshape((480,640,3))          # notice how height specified first , width     if image not none:         cv2.imshow('video', image)      if cv2.waitkey(1) & 0xff == ord('q'):         break     pipe.stdout.flush()  cv2.destroyallwindows() 

no need change other thing on raspberry pi side script.

this worked charm me. video lag negligible. hope helps.


Comments

Popular posts from this blog

python - cx_oracle unable to find Oracle Client -

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -