C++/OpenCV Streaming Camera-Video/Images (MJPEG) from Socket into Browser (Windows 8.1)

◇◆丶佛笑我妖孽 提交于 2019-12-02 19:49:21

I got it done myself now, was making a few mistakes here and there.

The most important part to get the image to show up was

a) to get a html header which is sent before sending the actual image so my browser knows what's gonna be sent

b) use imencode to save the image in a buffer and send that buffer instead of the image itself

I also don't save the frame anywhere but just take it right from my camera input so that kinda shortens it as well.

To get it done with mjpegs I just had to add another header before, that tells the "client" that there's gonna be multiple images being sent, seperated by a certain border:

sprintf(head, "HTTP/1.1 200 OK\r\nContent-Type: multipart/x-mixed-replace;boundary=informs\r\n\r\n");
send(socket,head,strlen(head), 0);

This helped a little, esp. with the header-part: http://nakkaya.com/2011/03/23/streaming-opencv-video-over-the-network-using-mjpeg/ (although it got me irritated at first 'cause I have never used nor seen clojure before.

Also this was really helpful: http://answers.opencv.org/question/6976/display-iplimage-in-webbrowsers/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!