Log in

View Full Version : trying to use usb webcam with opencv


Bernstern
21-02-2016, 16:20
Hello,

My team has been trying to use the Tower tracker program to little avail, but our hardest challenge is using our Microsoft webcam as the vision input. I checked out mjpeg streamer but couldn't understand it and have gotten no where with it. Any help would be greatly appreciated/

Noviv
21-02-2016, 18:46
My team isn't using the Tower Tracker program, so I can't help you with that, sorry.

But, if you are using OpenCV in C/C++, all you should have to do is declare a new VideoCapture and use the Mat that you get from the device. You can then play around with the Mat using OpenCV functions (just google what you want to do).


#include "opencv2/opencv.hpp"

int main() {
VideoCapture cap(0);
Mat frame;

namedWindow("Webcam");

while (true) {
cap >> frame;

//opencv functions go here

imshow("Webcam", frame);
if (waitKey(30) >= 0) {
break;
}
}

cap.release();
}


If you have another webcam on the computer/device you are running this program on, just increase 0 to 1, 2, etc until you get the right device.