2013-08-08 2 views
3

this 페이지에 코드가 있습니다. 그것은 char* 및 복수 IplImage* 인수로 입력 한 다음 모든 이미지를 하나의 창에 표시하는 깔끔한 기능입니다.OpenCV를 사용하여 하나의 이미지와 하나의 비디오를 하나의 창에 표시하는 방법

하나의 이미지와 하나의 비디오로 동일하게 작업하고 싶습니다. 따라서, 웹 캠 입력을 초기화하기 위해 main 함수를 변경하고 위의 함수로 호출을 수정하는 것 외에 무엇을 변경해야합니까?

내 주요 기능은 다음과 이에

int main() { 

    IplImage *img1 = cvLoadImage("image1.png"); 

    CvCapture* capture = cvCaptureFromCAM(0); 
    if (!capture) { 
    fprintf(stderr, "ERROR: capture is NULL \n"); 
    getchar(); 
    return -1; 
    } 
    // Create a window in which the captured images will be presented 
    cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE); 
    // Show the image captured from the camera in the window and repeat 
    while (1) { 
    // Get one frame 
    IplImage* frame = cvQueryFrame(capture); 
    if (!frame) { 
     fprintf(stderr, "ERROR: frame is null...\n"); 
     getchar(); 
     break; 
    } 
    //cvShowImage("mywindow", frame); 
    cvShowManyImages("Image", 2, img1, frame); 
    // Do not release the frame! 
    //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version), 
    //remove higher bits using AND operator 
    if ((cvWaitKey(10) & 255) == 27) break; 
    } 
    // Release the capture device housekeeping 
    cvReleaseCapture(&capture); 
    cvDestroyWindow("mywindow"); 

    return 0; 
} 

문제는 단지 비디오의 첫 번째 프레임을 나타내고있다. 다음 프레임을 얻으려면 계속 esc을 눌러야합니다.

+0

이 새 이미지에 프레임을 복사하여 두 이미지를 그리는 시도? – Manuel

+0

이미지와 함께 재생되는 비디오를보고 싶습니다. – wrahool

답변

1

당신이 필요로하는이 작품 :

void cvShowManyImages(char* title, int nArgs, ...) { 

    // img - Used for getting the arguments 
    IplImage *img; 

    // DispImage - the image in which input images are to be copied 
    IplImage *DispImage; 

    int size; 
    int i; 
    int m, n; 
    int x, y; 

    // w - Maximum number of images in a row 
    // h - Maximum number of images in a column 
    int w, h; 

    // scale - How much we have to resize the image 
    float scale; 
    int max; 

    // If the number of arguments is lesser than 0 or greater than 12 
    // return without displaying 
    if(nArgs <= 0) { 
     printf("Number of arguments too small....\n"); 
     return; 
    } 
    else if(nArgs > 12) { 
     printf("Number of arguments too large....\n"); 
     return; 
    } 
    // Determine the size of the image, 
    // and the number of rows/cols 
    // from 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 a new 3 channel image 
    DispImage = cvCreateImage(cvSize(100 + size*w, 60 + size*h), 8, 3); 
    cvZero(DispImage); 
    // Used to get the arguments passed 
    va_list args; 
    va_start(args, nArgs); 

    // Loop for nArgs number of arguments 
    for (i = 0, m = 20, n = 20; i < nArgs; i++, m += (20 + size)) { 

     // Get the Pointer to the IplImage 
     img = va_arg(args, IplImage*); 

     // Check whether it is NULL or not 
     // If it is NULL, release the image, and return 
     if(img == 0) { 
      printf("Invalid arguments"); 
      cvReleaseImage(&DispImage); 
      return; 
     } 

     // Find the width and height of the image 
     x = img->width; 
     y = img->height; 

     // Find whether height or width is greater in order to resize the image 
     max = (x > y)? x: y; 

     // Find the scaling factor to resize the image 
     scale = (float) ((float) max/size); 

     // Used to Align the images 
     if(i % w == 0 && m!= 20) { 
      m = 20; 
      n+= 20 + size; 
     } 

     // Set the image ROI to display the current image 
     cvSetImageROI(DispImage, cvRect(m, n, (int)(x/scale), (int)(y/scale))); 

     // Resize the input image and copy the it to the Single Big Image 
     cvResize(img, DispImage); 

     // Reset the ROI in order to display the next image 
     cvResetImageROI(DispImage); 
    } 

    // Create a new window, and show the Single Big Image 
    // cvNamedWindow(title, 1); 
    cvShowImage(title, DispImage); 

    // cvWaitKey(20); 


    // End the number of arguments 
    va_end(args); 

    // Release the Image Memory 
    cvReleaseImage(&DispImage); 
} 
int main() { 

    IplImage *img1 = cvLoadImage("d:\\ImagesForTest\\cat.bmp"); 

    CvCapture* capture = cvCaptureFromCAM(0); 
    if (!capture) { 
     fprintf(stderr, "ERROR: capture is NULL \n"); 
     getchar(); 
     return -1; 
    } 
    // Create a window in which the captured images will be presented 
    cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE); 
    // Show the image captured from the camera in the window and repeat 
    while (1) { 
     // Get one frame 
     IplImage* frame = cvQueryFrame(capture); 
     if (!frame) { 
      fprintf(stderr, "ERROR: frame is null...\n"); 
      getchar(); 
      break; 
     } 
     //cvShowImage("mywindow", frame); 
     cvShowManyImages("Image", 2, img1, frame); 
     // Do not release the frame! 
     //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version), 
     //remove higher bits using AND operator 
     if ((cvWaitKey(10) & 255) == 27) break; 
    } 
    // Release the capture device housekeeping 
    cvReleaseCapture(&capture); 
    cvDestroyAllWindows(); 

    return 0; 
} 
+0

감사! 그것은 작동합니다! :) – wrahool

관련 문제