c++ - How to display one image and one video in one window using OpenCV -
i came upon piece of code on this page. it's neat function takes input, char*
, multiple iplimage*
arguments , displays images in 1 window.
i want same 1 image , 1 video. so, apart changing main function initialise web cam input, , modifying call above function, else need change?
my main function :
int main() { iplimage *img1 = cvloadimage("image1.png"); cvcapture* capture = cvcapturefromcam(0); if ( !capture ) { fprintf( stderr, "error: capture null \n" ); getchar(); return -1; } // create window in captured images presented cvnamedwindow( "mywindow", cv_window_autosize ); // show image captured camera in window , repeat while ( 1 ) { // 1 frame iplimage* frame = cvqueryframe( capture ); if ( !frame ) { fprintf( stderr, "error: frame null...\n" ); getchar(); break; } //cvshowimage( "mywindow", frame ); cvshowmanyimages("image", 2, img1, frame); // not release frame! //if esc key pressed, key=0x10001b under opencv 0.9.7(linux version), //remove higher bits using , operator if ( (cvwaitkey(10) & 255) == 27 ) break; } // release capture device housekeeping cvreleasecapture( &capture ); cvdestroywindow( "mywindow" ); return 0; }
the problem is, shows first frame of video. , need keep pressing esc
next frame.
this works need:
void cvshowmanyimages(char* title, int nargs, ...) { // img - used getting arguments iplimage *img; // dispimage - image in input images copied iplimage *dispimage; int size; int i; int m, n; int x, y; // w - maximum number of images in row // h - maximum number of images in column int w, h; // scale - how have resize image float scale; int max; // if number of arguments lesser 0 or greater 12 // return without displaying if(nargs <= 0) { printf("number of arguments small....\n"); return; } else if(nargs > 12) { printf("number of arguments large....\n"); return; } // determine size of image, // , number of rows/cols // number of arguments else if (nargs == 1) { w = h = 1; size = 300; } else if (nargs == 2) { w = 2; h = 1; size = 300; } else if (nargs == 3 || nargs == 4) { w = 2; h = 2; size = 300; } else if (nargs == 5 || nargs == 6) { w = 3; h = 2; size = 200; } else if (nargs == 7 || nargs == 8) { w = 4; h = 2; size = 200; } else { w = 4; h = 3; size = 150; } // create new 3 channel image dispimage = cvcreateimage( cvsize(100 + size*w, 60 + size*h), 8, 3 ); cvzero(dispimage); // used arguments passed va_list args; va_start(args, nargs); // loop nargs number of arguments (i = 0, m = 20, n = 20; < nargs; i++, m += (20 + size)) { // pointer iplimage img = va_arg(args, iplimage*); // check whether null or not // if null, release image, , return if(img == 0) { printf("invalid arguments"); cvreleaseimage(&dispimage); return; } // find width , height of image x = img->width; y = img->height; // find whether height or width greater in order resize image max = (x > y)? x: y; // find scaling factor resize image scale = (float) ( (float) max / size ); // used align images if( % w == 0 && m!= 20) { m = 20; n+= 20 + size; } // set image roi display current image cvsetimageroi(dispimage, cvrect(m, n, (int)( x/scale ), (int)( y/scale ))); // resize input image , copy single big image cvresize(img, dispimage); // reset roi in order display next image cvresetimageroi(dispimage); } // create new window, , show single big image // cvnamedwindow( title, 1 ); cvshowimage( title, dispimage); // cvwaitkey(20); // end number of arguments va_end(args); // release image memory cvreleaseimage(&dispimage); } int main() { iplimage *img1 = cvloadimage("d:\\imagesfortest\\cat.bmp"); cvcapture* capture = cvcapturefromcam(0); if ( !capture ) { fprintf( stderr, "error: capture null \n" ); getchar(); return -1; } // create window in captured images presented cvnamedwindow( "mywindow", cv_window_autosize ); // show image captured camera in window , repeat while ( 1 ) { // 1 frame iplimage* frame = cvqueryframe( capture ); if ( !frame ) { fprintf( stderr, "error: frame null...\n" ); getchar(); break; } //cvshowimage( "mywindow", frame ); cvshowmanyimages("image", 2, img1, frame); // not release frame! //if esc key pressed, key=0x10001b under opencv 0.9.7(linux version), //remove higher bits using , operator if ( (cvwaitkey(10) & 255) == 27 ) break; } // release capture device housekeeping cvreleasecapture( &capture ); cvdestroyallwindows(); return 0; }
Comments
Post a Comment