Grab webcam using C++ and OpenCV:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// OpenCV Diplay camera. https://talkera.org/opencv
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main( int argc, const char** argv )
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame;
imshow("webcam", frame);
if(waitKey(30) >= 0) break;
}
}
|
Grab webcam using Python and OpenCV:
1
2
3
4
5
6
7
8
9
10
|
from cv2 import *
# initialize the camera. talkera.org/opencv
cam = VideoCapture(0) # 0 -> index of camera
while 1:
s, img = cam.read()
if s: # frame captured without any errors
namedWindow("cam-test",CV_WINDOW_AUTOSIZE)
imshow("cam-test",img)
waitKey(100)
|