how to send a live stream in opencv

asked 2014-07-17 00:59:43 -0500

wzj gravatar image

Hi. I try to send a live stream from videocapture directly. But it appear error : message too long Do i need process the stream before sending? I hope someone can do me a favor . THX in advance. here is my testing code: import cv2 from socket import *

cap = cv2.VideoCapture(0)

sock = socket(AF_INET, SOCK_DGRAM)

while (cap.isOpend()): t, frame = ser.sendto(frame, addr)

cap.release() cv2.destoryAllWindows()

edit retag flag offensive close merge delete


duplicate of your last question. close the other one ?

berak gravatar imageberak ( 2014-07-17 01:08:31 -0500 )edit

eh... what do you mean?

wzj gravatar imagewzj ( 2014-07-17 01:39:43 -0500 )edit

better to have only 1 question with the same topic here, else it gets pretty confusing, no ?

berak gravatar imageberak ( 2014-07-17 01:45:26 -0500 )edit

Got it ! so could you anwser my question PLS

wzj gravatar imagewzj ( 2014-07-17 01:48:00 -0500 )edit

@wzj Check out the answer here might be helpful.

Haris gravatar imageHaris ( 2014-07-17 01:51:37 -0500 )edit

wzj, there's no simple answer.

  • you can't just take the adress of a cv::Mat, and send it out. it's a composite object, containing pointers, vtables and what not, so now you need some kind of protocol. most simple one would be: rows,cols,type,pixels.
  • streaming uncompressed pixels to a network is a bad idea, a single 640x480x3 frame is 1mb already. way better use imencode, and send a jpg or png. (and you still need a protocol for this, as it's now variable length)
  • what would be on the other side of the line ? you need to write out something, that your client can digest.
  • a server has to accept internet connections(blocking) and process video at the same time. so you either need threads, select(3), or use udp even.
berak gravatar imageberak ( 2014-07-17 02:03:30 -0500 )edit

thank you so much

wzj gravatar imagewzj ( 2014-07-17 03:06:43 -0500 )edit

sure that will work. just the strings are a bad idea. if you can flatten the numpy frame into one long 1d array, then socket.write(bytearray( frame1d ) )

berak gravatar imageberak ( 2014-07-17 10:43:16 -0500 )edit

eh... it use string to transmission. There is some code that I do not really understand sock.send( str(len(stringData)).ljust(16)); why need do this

wzj gravatar imagewzj ( 2014-07-17 23:08:08 -0500 )edit