Ask Your Question

capture image with webcam on ubuntu

asked 2013-02-11 06:01:06 -0500

niki gravatar image

I m very new to ubuntu and open cv..I( hav finishe installing opencv.. can anyone tell me the proper instructions to compile a program in ubuntu using opencv.. I tried out this code for image capture

include <iostream>

include <cxcore.h>

include <highgui.h>

int main(int argc, char* argv[]) { CvCapture* camera = 0; if (argc > 1) camera = cvCreateFileCapture(argv[1]); else { camera = cvCreateCameraCapture(-1); // Use the default camera

IplImage* frame = 0; IplImage img;

cvNamedWindow("window_name", 1);

while (cvGetWindowHandle("window_name")) { //Use while (true) if you are on Mac

frame = cvQueryFrame(&camera); //Be careful not to change the value or to free the "frame" variable

cvSaveImage("webcam.jpg", &frame);
cvShowImage("window_name", &frame);

keyPressed = cvWaitKey(2);

if (keyPressed == 27)


cvReleaseCapture(&camera); return 0; }

And i m getting some errors for this like

camera1.cpp: In function ‘int main(int, char)’: camera1.cpp:19:32: error: cannot convert ‘CvCapture’ to ‘CvCapture’ for argument ‘1’ to ‘IplImage cvQueryFrame(CvCapture*)’ camera1.cpp:25:5: error: ‘keyPressed’ was not declared in this scope camera1.cpp:13:17: warning: unused variable ‘img’ [-Wunused-variable] camera1.cpp:33:1: error: expected ‘}’ at end of input

please tell me the basic steps and the errors above..

edit retag flag offensive close merge delete


can you please reformat the question, so it's more readable ? edit it, highlight(select) the code part, and press the '0101001' button, same for the error msg. some important details, like * and & got lost

berak gravatar imageberak ( 2013-02-11 06:20:31 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2013-02-11 06:09:07 -0500

berak gravatar image
CvCapture* camera;  // camera is a pointer already

//so change:
frame = cvQueryFrame(&camera);
frame = cvQueryFrame(camera);


int keyPressed = cvWaitKey(2);
edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2013-02-11 06:01:06 -0500

Seen: 1,014 times

Last updated: Feb 11 '13