int main(int argc, char* argv[]) { int chessboard_search = 0; cvNamedWindow("leftimage", CV_WINDOW_AUTOSIZE); cvNamedWindow("rightimage", CV_WINDOW_AUTOSIZE); CvCapture *capture_left, *capture_right; printf("Using webcam\n"); capture_left = cvCreateCameraCapture(CAM_LEFT ); capture_right = cvCreateCameraCapture(CAM_RIGHT); /* cvSetCaptureProperty(capture_left, CV_CAP_PROP_FRAME_WIDTH, SCREEN_WIDTH/2); cvSetCaptureProperty(capture_right, CV_CAP_PROP_FRAME_WIDTH, SCREEN_WIDTH/2); */ if (capture_left == NULL) fatal("can't find left webcam (seen from computers eyes)"); if (capture_right == NULL) fatal("can't find right webcam (seen from computers eyes)"); IplImage *frame_left, *frame_right; /* process frames */ while (1) { /* get next frame */ frame_left = cvQueryFrame(capture_left); frame_right = cvQueryFrame(capture_right); if (!frame_left || !frame_right) break; /* search for chessboard */ if (chessboard_search) { chessboard_finder(frame_left); chessboard_finder(frame_right); } /* show frames in window */ cvShowImage("leftimage", frame_left); cvShowImage("rightimage", frame_right); char c = cvWaitKey(33); if (c == 27) break; if (c == 99) { /* pushed c */ chessboard_search = !(chessboard_search); printf("Chessboard search is turned %s.\n", (chessboard_search) ? "on" : "off"); } } cvReleaseCapture(&capture_left); cvReleaseCapture(&capture_right); cvDestroyWindow("leftimage"); cvDestroyWindow("rightimage"); return 0; }
//-------------------------------------------------------------------------------------- // Name: CVInit() // Desc: Initializate OpenCV //-------------------------------------------------------------------------------------- bool GLCVUtils::CVInit (int mode) { if (mode == VIDEO_FILE) { capture = cvCreateFileCapture ("Ratatouille.avi"); if (! capture) printf ("\n\n\nerror creating file capture\n\n\n"); } else if (mode == CAMERA) { // create capture capture = cvCreateCameraCapture (0); if (! capture) { printf ("\nError creating capture"); return false; } // sets camera (hardware) resolution cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_WIDTH, TEXTURE_W); cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_HEIGHT, TEXTURE_H); } else { printf ("\nWrong Mode"); } return true; }
int _tmain(int argc, _TCHAR* argv[]) { CvCapture* kameraku; kameraku=cvCreateCameraCapture(1); assert(kameraku!=NULL); IplImage* framemurah;//=cvQueryFrame(kameraku); IplImage* framegray;//=cvCreateImage(cvSize( framemurah->width, framemurah->height ), IPL_DEPTH_8U, 1 ); //cvCvtColor(framemurah,framegray,CV_RGB2GRAY ); while(1){ framemurah=cvQueryFrame(kameraku); //if(!framemurah) break; cvNamedWindow("Kamera1", CV_WINDOW_AUTOSIZE); cvShowImage("Kamera1", framemurah); char c = cvWaitKey(33); framegray=cvCreateImage(cvSize( framemurah->width, framemurah->height ), IPL_DEPTH_8U, 1 ); cvCvtColor(framemurah,framegray,CV_RGB2GRAY);//konvert RGB to Gray //cvThreshold(framemurah,framegray, g_thresh, 255, CV_THRESH_BINARY); cvThreshold(framegray,framegray, 50, 255, CV_THRESH_BINARY); cvNamedWindow("Kamera2", CV_WINDOW_AUTOSIZE); cvShowImage("Kamera2", framegray); char v = cvWaitKey(33); //if(c==27) break; } cvReleaseCapture(&kameraku); cvDestroyWindow("Kamera1"); cvDestroyWindow("Kamera2"); }
int main(int args,char *argv[]){ // 视频结构 CvCapture *capture = NULL; // 获得摄像头数据 // CV_CAP_ANY 自动 capture = cvCreateCameraCapture(CV_CAP_ANY); if (!capture) { exit(0); } cvNamedWindow("camera",CV_WINDOW_AUTOSIZE); // 图片结构 IplImage *image = NULL; while(image = cvQueryFrame(capture)){ // 反色处理 cvNot(image,image); // 现实图像 cvShowImage("camera",image); // 监听键盘输入,如果有输入则跳出while if( cvWaitKey(2) >= 0 ) break; } // 释放视频 cvReleaseCapture(&capture); return 0; }
void ColibriMainWindow::on_camButton_toggled(bool checked) { if(!checked) { if(m_timer.isActive()) m_timer.stop(); // Stop thread if(m_pColibriThread) { m_pColibriThread->stop(); m_pColibriThread->setCapture(NULL); } cvReleaseCapture(&capture); capture = NULL; return; } if(!capture) { int retry = 0; do { capture = cvCreateCameraCapture (retry); fprintf(stderr, "[Colibri] %s:%d : capture #%d =%p\n", __func__, __LINE__, retry, capture); retry++; } while(!capture && retry < 5); } if(!capture) { QMessageBox::critical(NULL, tr("No webcam"), tr("Unable to find webcam. Please try disconnect/reconnect.")); return ; } startBackgroundThread(); }
// Get the resolutions of a device void Cam::getDeviceInfo(int d){ CvCapture *cap = cvCreateCameraCapture(d); num_resolutions = 0; for(int i=0; i<N_RESOLUTIONS; i++){ // Set actual values of resolution cvSetCaptureProperty( cap, CV_CAP_PROP_FRAME_WIDTH, c_resolutions[i].x ); cvSetCaptureProperty( cap, CV_CAP_PROP_FRAME_HEIGHT, c_resolutions[i].y ); // Compare the actual resolution value with the last accepted value (Width and Height) if( c_resolutions[i].x == cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH) && c_resolutions[i].y == cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT) ){ resolutions[num_resolutions].x = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH); resolutions[num_resolutions].y = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT); num_resolutions++; } } cvReleaseCapture(&cap); /* for(int i=0; i<num_resolutions; i++){ std::cout << i << ": " << resolutions[i].x << ", " << resolutions[i].y << std::endl; } */ }
int main() { int thresh=25; CvCapture* capture; capture = cvCreateCameraCapture(-1); IplImage *frame,*res; char win[]="video_stream"; char win2[]="outline_feed"; cvNamedWindow(win,CV_WINDOW_AUTOSIZE); cvNamedWindow(win2,CV_WINDOW_AUTOSIZE); cvCreateTrackbar("Threshold",win2,&thresh,128); while(1) { frame=cvQueryFrame(capture); res = findedge(frame,thresh); clearnoise(res,0, 3); clearnoise(res,1, 3); cvShowImage(win,frame); cvShowImage(win2,res); if(cvWaitKey(50)==27) break; } cvReleaseImage(&frame); cvReleaseImage(&res); cvReleaseCapture(&capture); cvDestroyWindow(win); cvDestroyWindow(win2); return 0; }
//////////////////////////////////////////////////////////////////////////// // MAIN //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /// /// Main program. /// int main( int argc, char *argv[] ) { CvCapture *video; IplImage *frame; char *win_name = "Captured Frame"; char key = 0; video = cvCreateCameraCapture( -1 ); // video = cvCreateFileCapture( argv[1] ); if ( !video ) { fprintf( stderr, "unable to capture source\n" ); exit( 1 ); } else { printf( "capture source opened.\n" ); } printCaptureProperties( video ); printf( "Press 'q' to quit.\n" ); while ( ( frame = cvQueryFrame( video ) ) && ( char ) key != 'q' ) { cvNamedWindow( win_name, 1 ); cvShowImage( win_name, frame ); key = cvWaitKey( 5 ); } cvDestroyWindow( win_name ); cvReleaseCapture( &video ); return 0; }
int main() { // Image & hsvImage //IplImage *hsv; // Video Capture CvCapture *capture; // Key for keyboard event char key; // Number of tracked pixels int nbPixels; // Next position of the object we overlay CvPoint objectNextPos; // Initialize the video Capture (200 => CV_CAP_V4L2) capture = cvCreateCameraCapture(200); // Check if the capture is ok if (!capture) { printf("Can't initialize the video capture.\n"); return -1; } // Create the windows cvNamedWindow("Test Color Tracking", CV_WINDOW_AUTOSIZE); cvNamedWindow("Test Mask", CV_WINDOW_AUTOSIZE); cvMoveWindow("Test Color Tracking", 0, 100); cvMoveWindow("Test Mask", 650, 100); // Mouse event to select the tracked color on the original image cvSetMouseCallback("Test Color Tracking", getObjectColor); // While we don't want to quit while(key != 'Q' && key != 'q') { // We get the current image image = cvQueryFrame(capture); // If there is no image, we exit the loop if(!image) continue; objectNextPos = binarisation(image, &nbPixels); addObjectToVideo(image, objectNextPos, nbPixels); // We wait 10 ms key = cvWaitKey(10); } // Destroy the windows we have created cvDestroyWindow("Test Color Tracking"); cvDestroyWindow("Test Mask"); // Destroy the capture cvReleaseCapture(&capture); return 0; }
int main(int argc, char *argv[]) { // Face detection if (initFacedetect() < 0) exit(-1); numImgs = argc - 1; imgPaths = argv + 1; if (numImgs == 0) { // Camera input //capture = cvCaptureFromCAM(-1); capture = cvCreateCameraCapture(-1); if (capture == NULL) { printf("Couldn't start camera\n"); exit(-1); } } cvNamedWindow("preview", 1); videoFunc(); cvDestroyWindow("preview"); if (numImgs == 0) cvReleaseCapture(&capture); deinit_opt_flow(); SDL_Quit(); return 0; }
int Qt_Gui_by_ABK (int a,char *b[]) { CvCapture *capture ; IplImage *frame=0; capture = cvCreateCameraCapture(0); int n = 0; //resoulution // cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH,1024); //cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT,768); QApplication app(a,b,true); QLabel label ; QSplashScreen * splash = new QSplashScreen; while(1) { frame = cvQueryFrame(capture); printf("the camera resoulution is %dx%d\n",frame->width,frame->height); cvCvtColor(frame,frame,CV_BGR2RGB); QImage image =QImage((uchar*)frame->imageData,frame->width,frame->height,QImage::Format_RGB888); splash->setPixmap(QPixmap::fromImage(image)); splash->show(); //label.update(); n++; } return app.exec(); }
int main( int argc, char** argv ) { cvNamedWindow( "Press Any Key to Quit", CV_WINDOW_AUTOSIZE ); CvCapture *capture = cvCreateCameraCapture(0); if( capture == NULL ) { printf( "\n!ERROR! - Could not open camera at /dev/video0\n\n" ); printf( "\nIf you are using VMWare, verify that the camera is connected" ); printf( "\nto the VMWare image by selecting 'Virtual Machine' in the" ); printf( "\nVMWare player window header above. " ); printf( "\nThen select 'removable devices' and verify your camera is connected.\n\n\n" ); assert(0); } IplImage *frame; while(1) { frame = cvQueryFrame( capture ); if( !frame ) break; cvShowImage( "Press Any Key to Quit", frame ); char c = cvWaitKey(33); if( c != -1 ) break; } cvReleaseCapture( &capture ); cvDestroyWindow( "Press Any Key to Quit" ); }
void VideoReader::useCamera(int idCamera) { auto tmp = cvCreateCameraCapture(idCamera); if( ! tmp ) throw Exception::buildException("Can't use this camera as source", "VideoReader", "useCamera", EPC); m_video = tmp; }
int main(int argc, char** argv) { CvCapture* capture = 0; IplImage* input = 0; IplImage* output = 0; int tick = 0, prev_tick = 0; double now = 0.0; CvFont font; char buffer[256]; const char* windowName = "median"; if (argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) { capture = cvCreateCameraCapture(argc == 2 ? argv[1][0] - '0' : 0); } else if (argc == 2) { capture = cvCreateFileCapture(argv[1]); } if (!capture) { fprintf(stderr, "ERROR: capture is NULL \n"); return (-1); } cvNamedWindow(windowName, CV_WINDOW_AUTOSIZE); cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0.0, 1, 0); input = cvQueryFrame(capture); if (!input) { fprintf(stderr, "Could not query frame...\n"); return (-1); } output = cvCreateImage(cvSize(input->width, input->height), IPL_DEPTH_8U, 3); while (1) { input = cvQueryFrame(capture); if (!input) { fprintf(stderr, "Could not query frame...\n"); break; } process(input, output); sprintf(buffer, "%3.1lfms", now / 1000); cvPutText(output, buffer, cvPoint(50, 150), &font, CV_RGB(255, 0, 0)); cvShowImage(windowName, output); //If a certain key pressed if (cvWaitKey(10) >= 0) { break; } tick = cvGetTickCount(); now = (tick - prev_tick) / cvGetTickFrequency(); prev_tick = tick; } cvReleaseImage(&output); cvReleaseCapture(&capture); cvDestroyWindow(windowName); return 0; }
void MyDisplay::camera_negatif() { capture = cvCreateCameraCapture(CV_CAP_ANY); while (1){ frame = cvQueryFrame(capture); img_nvg = cvCreateImage(cvGetSize(frame), frame->depth, 1); //conversion en niveau de gris cvConvertImage(frame, img_nvg, 0); stretch_histogram_NVG(img_nvg); negatif(img_nvg); //frame = negatif(frame); cvShowImage("test", img_nvg); int key = cvWaitKey(1); if (key == 'q') { break; } else { //nothing to do } } cvReleaseCapture(&capture); }
int init_fish(){ cvNamedWindow( "set_HSV", CV_WINDOW_NORMAL); cvNamedWindow( "Camera", CV_WINDOW_NORMAL); set_mouse_bar("Camera"); g_capture = cvCreateCameraCapture( 0 ); if(g_capture == NULL){ printf("no camra in comp\n"); exit(0); } frame = cvQueryFrame( g_capture ); cvCvtColor(frame,frame,CV_RGB2HSV); cl_frame = cvCloneImage(frame); cl_frame_temp = cvCloneImage(frame); frameSize = cvGetSize(frame); gr_frame = cvCreateImage(frameSize,IPL_DEPTH_8U,1); // set_trac_bar("set_HSV"); onTrackbarSlide(0); g_msPrm.isDrawing = 0; g_msPrm.image = cl_frame; g_msPrm.box = cvRect( 0, 0, 1, 1 ); mouse("Camera",&g_msPrm); return 0; }
void the_project::project_init() { car_of_pro = new the_car(); //camera 480*640 for_cam = cvCreateCameraCapture(1); for_video = cvCreateFileCapture("test.avi"); image_size = cvSize(cvGetCaptureProperty(for_cam,3),cvGetCaptureProperty(for_cam,4)); wr1 = cvCreateVideoWriter("record_ori.avi",CV_FOURCC('X','V','I','D') ,15,image_size); wr2 = cvCreateVideoWriter("record_cha.avi",CV_FOURCC('X','V','I','D') ,15,image_size); newpoints[0]=cvPoint2D32f(0,0); newpoints[1]=cvPoint2D32f(0,image_size.height); newpoints[2]=cvPoint2D32f(image_size.width,image_size.height); newpoints[3]=cvPoint2D32f(image_size.width,0); red_min=200; rg_max=100; rb_max=100; green_min=200; gb_max=100; gr_max=100; }
int main(int argc, char **argv) { /* init camera */ CvCapture* pCapture = cvCreateCameraCapture(0); cvSetCaptureProperty(pCapture, CV_CAP_PROP_FRAME_WIDTH, 320); cvSetCaptureProperty(pCapture, CV_CAP_PROP_FRAME_HEIGHT, 240); //cvSetCaptureProperty(pCapture, CV_CAP_PROP_FPS, 5); IplImage *pFrame = 0; if (NULL == pCapture) { fprintf(stderr, "Can't initialize webcam!\n"); return 1; } pFrame = cvQueryFrame(pCapture); // query a frame if(NULL == pFrame) { fprintf(stderr, "Can't get a frame!\n" ); return 1; } const char *pImageFileName = "webcam.jpg"; cvSaveImage(pImageFileName, pFrame); cvReleaseCapture(&pCapture); // free memory return 0; }
int main() { CvCapture *capture; IplImage *frame; capture=cvCreateCameraCapture(0); cvNamedWindow("Webcam",0); CvVideoWriter *writer = NULL; char AviFileName[]="Output.avi"; int AviForamt = 1; int FPS = 20; CvSize AviSize = cvSize(640,480); int AviColor = 1; writer=cvCreateVideoWriter(AviFileName, CV_FOURCC('P','I','M','1'), FPS,AviSize,AviColor); if(writer == NULL) printf("writer null..\n"); int i=0; while(true) { frame = cvQueryFrame(capture); cvWriteFrame(writer,frame); cvShowImage("Webcam",frame); printf("%d\n",i); if(cvWaitKey(20)>0) break; i++; } cvReleaseCapture(&capture); cvReleaseVideoWriter(&writer); cvDestroyWindow("Webcam"); }
int main() { int low=0,high=128; CvCapture* capture; capture = cvCreateCameraCapture(-1); IplImage *frame,*grey,*res; char win[]="video_stream"; char win2[]="outline_feed"; cvNamedWindow(win,CV_WINDOW_AUTOSIZE); cvNamedWindow(win2,CV_WINDOW_AUTOSIZE); cvCreateTrackbar("Low",win2,&low,128); cvCreateTrackbar("High",win2,&high,128); frame=cvQueryFrame(capture); grey=cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,1); res=cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,1); while(1) { frame=cvQueryFrame(capture); cvCvtColor(frame,grey,CV_BGR2GRAY); cvCanny(grey,res,low,high,3); cvShowImage(win,frame); cvShowImage(win2,res); char c=cvWaitKey(33); if(c==27) break; } cvReleaseImage(&frame); cvReleaseImage(&res); cvReleaseCapture(&capture); cvDestroyWindow(win); cvDestroyWindow(win2); return 0; }
int main (int argc, char **argv) { CvCapture *capture = 0; IplImage *frame = 0; CvVideoWriter *writer; int c, num = 0; //CvFont font; //char str[64]; double fps, width, height; if ( argc == 1 || (argc >= 2 && strlen (argv[1]) == 1 && isdigit (argv[1][0])) ) { capture = cvCreateCameraCapture (argc == 2 ? argv[1][0] - '0' : 0); fps = 20.0; width = 320; height = 240; //fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS); //cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_WIDTH, width); //cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_HEIGHT, height); } else if ( argc >= 2 ) { capture = cvCaptureFromFile(argv[1]); fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS); width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH); height = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT); } printf ("fps=%f width=%f height=%f\n", fps, width, height); printf ("Write to cap.avi. Finish with Esc.\n"); // FourCC http://www.fourcc.org/codecs.php //writer = cvCreateVideoWriter( "cap.avi", // CV_FOURCC('D','I','V','X'), // fps, cvSize((int)width,(int)height) ); writer = cvCreateVideoWriter( "cap.avi", -1, fps, cvSize((int)width,(int)height) ); //cvInitFont (&font, CV_FONT_HERSHEY_COMPLEX, 0.7, 0.7); cvNamedWindow ("Capture", CV_WINDOW_AUTOSIZE); while (1) { frame = cvQueryFrame (capture); if( frame == NULL ) break; //snprintf (str, 64, "%03d[frame]", num); //cvPutText (frame, str, cvPoint (10, 20), &font, CV_RGB (0, 255, 100)); cvWriteFrame (writer, frame); cvShowImage ("Capture", frame); num++; c = cvWaitKey (10); if (c == 'q') // exit break; } cvReleaseVideoWriter (&writer); cvReleaseCapture (&capture); cvDestroyWindow ("Capture"); return 0; }
int main (int argc, char **argv) { CvCapture *capture = 0; IplImage *frame = 0; double w = 320, h = 240; int c; // (1)コマンド引数によって指定された番号のカメラに対するキャプチャ構造体を作成する if (argc == 1 || (argc == 2 && strlen (argv[1]) == 1 && isdigit (argv[1][0]))) capture = cvCreateCameraCapture (argc == 2 ? argv[1][0] - '0' : 0); /* この設定は,利用するカメラに依存する */ // (2)キャプチャサイズを設定する. //cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_WIDTH, w); //cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_HEIGHT, h); cvNamedWindow ("Capture", CV_WINDOW_AUTOSIZE); // (3)カメラから画像をキャプチャする { IplImage *src_img_gray, *tmp_img_gray, *dst_img_gray; // (a) 画像処用の画像データを確保 frame = cvQueryFrame (capture); frame = cvQueryFrame (capture); frame = cvQueryFrame (capture); tmp_img_gray = cvCreateImage(cvGetSize(frame), IPL_DEPTH_16S, 1); src_img_gray = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1); dst_img_gray = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1); while (1) { frame = cvQueryFrame (capture); // (b)グレイ画像を作成 cvCvtColor(frame, src_img_gray, CV_BGR2GRAY); // (c)Edge処理 if ( 0 ) { cvCanny (src_img_gray, dst_img_gray, 50.0, 200.0, 3); }else{ cvLaplace (src_img_gray, tmp_img_gray, 5); cvConvertScaleAbs(tmp_img_gray, dst_img_gray, 1, 0); } // (d)結果を表示する cvShowImage ("Capture", dst_img_gray); c = cvWaitKey (10); if (c == '\x1b') break; } } cvReleaseCapture (&capture); cvDestroyWindow ("Capture"); return 0; }
int main(int argc, char* argv[]) { board_w = 5; // Board width in squares board_h = 8; // Board height n_boards = 8; // Number of boards int board_n = board_w * board_h; CvSize board_sz = cvSize( board_w, board_h ); CvCapture* capture = cvCreateCameraCapture( 0 ); assert( capture ); cvNamedWindow( "Calibration" ); // Allocate Sotrage CvMat* image_points = cvCreateMat( n_boards*board_n, 2, CV_32FC1 ); CvMat* object_points = cvCreateMat( n_boards*board_n, 3, CV_32FC1 ); CvMat* point_counts = cvCreateMat( n_boards, 1, CV_32SC1 ); CvMat* intrinsic_matrix = cvCreateMat( 3, 3, CV_32FC1 ); CvMat* distortion_coeffs = cvCreateMat( 5, 1, CV_32FC1 ); CvPoint2D32f* corners = new CvPoint2D32f[ board_n ]; int corner_count; int successes = 0; int step, frame = 0; IplImage *image = cvQueryFrame( capture ); IplImage *gray_image = cvCreateImage( cvGetSize( image ), 8, 1 ); // Capture Corner views loop until we've got n_boards // succesful captures (all corners on the board are found) while( successes < n_boards ){ // Skp every board_dt frames to allow user to move chessboard if( frame++ % board_dt == 0 ){ // Find chessboard corners: int found = cvFindChessboardCorners( image, board_sz, corners, &corner_count, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS ); // Get subpixel accuracy on those corners cvCvtColor( image, gray_image, CV_BGR2GRAY ); cvFindCornerSubPix( gray_image, corners, corner_count, cvSize( 11, 11 ), cvSize( -1, -1 ), cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 )); // Draw it cvDrawChessboardCorners( image, board_sz, corners, corner_count, found ); cvShowImage( "Calibration", image ); // If we got a good board, add it to our data if( corner_count == board_n ){ step = successes*board_n; for( int i=step, j=0; j < board_n; ++i, ++j ){ CV_MAT_ELEM( *image_points, float, i, 0 ) = corners[j].x; CV_MAT_ELEM( *image_points, float, i, 1 ) = corners[j].y; CV_MAT_ELEM( *object_points, float, i, 0 ) = j/board_w; CV_MAT_ELEM( *object_points, float, i, 1 ) = j%board_w; CV_MAT_ELEM( *object_points, float, i, 2 ) = 0.0f; } CV_MAT_ELEM( *point_counts, int, successes, 0 ) = board_n; successes++; } }
int main(int argc, char *argv[]) { int camera_id = -1; if(argc == 2) { if(0 == strcmp(argv[1], "-h")) { fprintf(stderr, "Usage: %s [CAMERA_ID]\n", argv[0]); exit(0); } else { camera_id = atoi(argv[1]); } } CvCapture* capture = cvCreateCameraCapture(camera_id); // camera id number (-1=any camera) if(capture == NULL) { fprintf(stderr, "Error: cannot find any camera.\n"); exit(1); } else { fprintf(stdout, "Press Esc to close the window.\n"); } // INIT cvNamedWindow("Input", CV_WINDOW_AUTOSIZE); cvNamedWindow("Output", CV_WINDOW_AUTOSIZE); IplImage* in_frame = cvQueryFrame(capture); CvSize frame_size = cvGetSize(in_frame); IplImage* out_frame_gray = cvCreateImage(frame_size, IPL_DEPTH_8U, 1); // 1 channel (black and white) // MAIN LOOP while(1) { in_frame = cvQueryFrame(capture); if(in_frame == NULL) break; cvCvtColor(in_frame, out_frame_gray, CV_BGR2GRAY); // RGB -> Gray cvShowImage("Input", in_frame); // display the frame cvShowImage("Output", out_frame_gray); // display the frame char c = cvWaitKey(frame_delay_ms); // wait for 40ms (40ms -> 25fps) if(c==27) break; // 27 = Esc key } // RELEASE POINTERS cvReleaseCapture(&capture); cvReleaseImage(&out_frame_gray); cvDestroyWindow("Input"); cvDestroyWindow("Output"); return 0; }
//============================================================================= int main(int argc, const char** argv) { //parse command line arguments char ftFile[256],conFile[256],triFile[256]; bool fcheck = false; double scale = 1; int fpd = -1; bool show = true; if(parse_cmd(argc,argv,ftFile,conFile,triFile,fcheck,scale,fpd)<0)return 0; //set other tracking parameters std::vector<int> wSize1(1); wSize1[0] = 7; std::vector<int> wSize2(3); wSize2[0] = 11; wSize2[1] = 9; wSize2[2] = 7; int nIter = 5; double clamp=3,fTol=0.01; FACETRACKER::Tracker model(ftFile); cv::Mat tri=FACETRACKER::IO::LoadTri(triFile); cv::Mat con=FACETRACKER::IO::LoadCon(conFile); //initialize camera and display window cv::Mat frame,gray,im; double fps=0; char sss[256]; std::string text; CvCapture* camera = cvCreateCameraCapture(CV_CAP_ANY); if(!camera)return -1; int64 t1,t0 = cvGetTickCount(); int fnum=0; cvNamedWindow("Face Tracker",1); std::cout << "Hot keys: " << std::endl << "\t ESC - quit" << std::endl << "\t d - Redetect" << std::endl; //loop until quit (i.e user presses ESC) bool failed = true; while(1){ //grab image, resize and flip IplImage* I = cvQueryFrame(camera); if(!I)continue; frame = I; if(scale == 1)im = frame; else cv::resize(frame,im,cv::Size(scale*frame.cols,scale*frame.rows)); cv::flip(im,im,1); cv::cvtColor(im,gray,CV_BGR2GRAY); //track this image std::vector<int> wSize; if(failed)wSize = wSize2; else wSize = wSize1; if(model.Track(gray,wSize,fpd,nIter,clamp,fTol,fcheck) == 0){ int idx = model._clm.GetViewIdx(); failed = false; Draw(im,model._shape,con,tri,model._clm._visi[idx]); }else{ if(show){cv::Mat R(im,cvRect(0,0,150,50)); R = cv::Scalar(0,0,255);} model.FrameReset(); failed = true; } //draw framerate on display image if(fnum >= 9){ t1 = cvGetTickCount(); fps = 10.0/((double(t1-t0)/cvGetTickFrequency())/1e+6); t0 = t1; fnum = 0; }else fnum += 1; if(show){ sprintf(sss,"%d frames/sec",(int)round(fps)); text = sss; cv::putText(im,text,cv::Point(10,20), CV_FONT_HERSHEY_SIMPLEX,0.5,CV_RGB(255,255,255)); } //show image and check for user input imshow("Face Tracker",im); int c = cvWaitKey(10); if(c == 27)break; else if(char(c) == 'd')model.FrameReset(); }return 0; }
int main(int argc, char* argv[]) { // получаем любую подключённую камеру CvCapture* capture = cvCreateCameraCapture(CV_CAP_ANY); //cvCaptureFromCAM( 0 ); assert( capture ); //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640);//1280); //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480);//960); // узнаем ширину и высоту кадра double width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH); double height = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT); printf("[i] %.0f x %.0f\n", width, height ); IplImage* frame=0; cvNamedWindow("capture", CV_WINDOW_AUTOSIZE); printf("[i] press Enter for capture image and Esc for quit!\n\n"); int counter=0; char filename[512]; char text_buf[32]; CvFont myFont; // cvInitFont(&myFont, СV_FONT_HERSHEY_PLAIN, 0.7, 1, 0, 1, 8); cvInitFont(&myFont, CV_FONT_HERSHEY_PLAIN, 2, 1, 0, 1, 8); while(true){ // получаем кадр frame = cvQueryFrame( capture ); //Filters cvtColor(frame, pic, CV_BGR2HSV); GaussianBlur(pic, pic, Size(7,7), 1.5, 1.5); sprintf(text_buf,"Hello!!!"); cvPutText(frame, text_buf, cvPoint(5,15), &myFont, cvScalar(0,0,255)); // показываем cvShowImage("capture", frame); char c = cvWaitKey(33); if (c == 27) { // нажата ESC break; } else if(c == 13) { // Enter // сохраняем кадр в файл sprintf(filename, "Image%d.jpg", counter); printf("[i] capture... %s\n", filename); cvSaveImage(filename, frame); counter++; } } // освобождаем ресурсы cvReleaseCapture( &capture ); cvDestroyWindow("capture"); return 0; }
bool VideoCapture::open(int index) { if (isOpened()) release(); icap = IVideoCapture_create(index); if (!icap.empty()) return true; cap.reset(cvCreateCameraCapture(index)); return isOpened(); }
void Image_Handler(FCGIContext * context, char * params) { int num = 0, width = 800, height = 600; FCGIValue val[] = { {"num", &num, FCGI_INT_T}, {"width", &width, FCGI_INT_T}, {"height", &height, FCGI_INT_T} }; if (!FCGI_ParseRequest(context, params, val, 3)) return; else if (num < 0 || num > 1) { FCGI_RejectJSON(context, "Invalid capture number"); return; } else if (width <= 0 || height <= 0) { FCGI_RejectJSON(context, "Invalid width/height"); return; } if (captureID != num) { if (captureID >= 0) { cvReleaseCapture(&capture); } capture = cvCreateCameraCapture(num); captureID = num; } cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width); cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height); static int p[] = {CV_IMWRITE_JPEG_QUALITY, 100, 0}; IplImage * frame = cvQueryFrame(capture); assert(frame != NULL); // CvMat stub; // CvMat * background = cvGetMat(frame, &stub, 0, 0); // CvMat *cv8u = cvCreateMat(frame->width, frame->height, CV_8U); // double min, max; // CvPoint a,b; // cvMinMaxLoc(background, &min, &max, &a, &b, 0); // double ccscale = 255.0/(max-min); // double ccshift = -min; //cvCvtScale(frame, cv8u, ccscale, ccshift); CvMat * jpg = cvEncodeImage(".jpg", frame, p); // Will this work? Log(LOGNOTE, "Sending image!"); FCGI_PrintRaw("Content-type: image/jpg\r\n"); FCGI_PrintRaw("Cache-Control: no-cache, no-store, must-revalidate\r\n\r\n"); //FCGI_PrintRaw("Content-Length: %d", jpg->rows*jpg->cols); FCGI_WriteBinary(jpg->data.ptr,1,jpg->rows*jpg->cols); cvReleaseMat(&jpg); cvReleaseImageHeader(&frame); }
BOOL WebcamGrabber::initialize(INT id) { _pPimpl->pCapture = cvCreateCameraCapture(id); if ( !_pPimpl->pCapture) return false; _pPimpl->id = id; return TRUE; }
CvCapture *init_camera() { CvCapture *capture = cvCreateCameraCapture(CV_CAP_ANY); if (!capture) { fprintf(stderr, "ERROR: capture is NULL\n"); exit(1); } return capture; }