Ask Your Question

Video over the Network

asked 2013-08-18 07:50:52 -0500

subhendusc gravatar image

I have a laptop running Windows 7 with Python 2.7. I have a webcam attached to the laptop. The laptop has no other webcam. The video is transmitted from this webcam using Yawcam software. The software can transmit videos in streaming , http and ftp protocols. I have arduino micro controller attached to it. I also have a python / twisted socket server running on it to communicate with my desktop. In my desktop I also have windows , python and openCV installed. I want to grab this video in real time and do image processing on it. I used this code to grab the video but with no success

import as cv

cv.NamedWindow("camera", 1)
capture = cv.CaptureFromCAM("ftp://@");
##capture = cv.CaptureFromCAM(0);
while True:
    img = cv.QueryFrame(capture)
    cv.ShowImage("camera", img)
    if cv.WaitKey(10) == 27:

Ideally i wanted to have openCV in my laptop and transmit videos in realtime using websockets . But I have no clue of doing it. Please help. The best solution would be having openCV at both the ends without any commercial software.

edit retag flag offensive close merge delete


  • please use the cv2 api, not the old one.
  • ftp sounds, like it's transmitting only single images, try the stream option instead
berak gravatar imageberak ( 2013-08-19 04:18:44 -0500 )edit

@berak - I have used cv2 also. and used http instead of ftp . But nothing is hapening. The error it is giving is Type Error : an integer is required. Can you provide me with a simple program or solution.

subhendusc gravatar imagesubhendusc ( 2013-08-19 08:21:39 -0500 )edit

3 answers

Sort by » oldest newest most voted

answered 2013-08-19 08:59:34 -0500

updated 2013-08-19 09:39:56 -0500

Very clear that it will give error...

CvCapture* cvCaptureFromCAM(int index)

Initializes capturing a video from a camera.
Parameter:    index – Index of the camera to be used. If there is only

one camera or it does not matter what camera is used -1 may be passed.

try that LINK

p.p. code, found somewhere... for example:

//MJPEG network stream to OpenCV 2

#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <iostream>

int main(int, char**) {
    cv::VideoCapture vcap;
    cv::Mat image;

    const std::string videoStreamAddress = "ip.ip.ip.ip";

    if(! {
        std::cout << "Error opening video stream or file" << std::endl;
        return -1;

    for(;;) {
        if(! {
            std::cout << "No frame" << std::endl;
        cv::imshow("Output Window", image);
        if(cv::waitKey(1) >= 0) break;
edit flag offensive delete link more

answered 2018-08-06 23:37:34 -0500

CT83 gravatar image

After months of searching the internet, this is what I came up with, I have neatly packaged it into classes, with unit tests and documentation as SmoothStream check it out, it was the only simple and working version of streaming I could find anywhere.

I used this code and wrapped mine around it.

import cv2
import zmq
import base64
import numpy as np

context = zmq.Context()
footage_socket = context.socket(zmq.SUB)
footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode(''))

while True:
        frame = footage_socket.recv_string()
        img = base64.b64decode(frame)
        npimg = np.fromstring(img, dtype=np.uint8)
        source = cv2.imdecode(npimg, 1)
        cv2.imshow("Stream", source)

    except KeyboardInterrupt:

import base64
import cv2
import zmq

context = zmq.Context()
footage_socket = context.socket(zmq.PUB)

camera = cv2.VideoCapture(0)  # init the camera

while True:
        grabbed, frame =  # grab the current frame
        frame = cv2.resize(frame, (640, 480))  # resize the frame
        encoded, buffer = cv2.imencode('.jpg', frame)
        jpg_as_text = base64.b64encode(buffer)

    except KeyboardInterrupt:
edit flag offensive delete link more

answered 2013-08-19 09:48:46 -0500

berak gravatar image

updated 2013-08-19 09:51:25 -0500

like Spas Hristov said, cv.CaptureFromCAM(int id) is used for (local) cameras, not for streams/urls.


   import cv2
   import numpy

   cap = cv2.VideoCapture("http://@")
   while cap.isOpened():
       _,frame =
       c = cv2.waitKey(1)
       if c == 27:
edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2013-08-18 07:50:52 -0500

Seen: 11,017 times

Last updated: Aug 19 '13