Ask Your Question

Revision history [back]

How to open next/prev image with key pg dn/pg up

Hi everyone, I have a question for you. I do simple application in MFC and OpenCV 2.0 that will perform a 3D reconstruction from several images. Each image represents the same object from different angles, this images are together in some folder, like My Pictures etc. I draw points on each image, that points represent the x,y coordinates that will be used later. When I open image in my application from some folder and select the points, I don't know how to open next image that comes in that folder. If I open the first image and select the points, how to open second image and select points on it, then comes third picture etc. I use switch case function, key pg dn is for next image, pg up is for previous image. Does anyone have an idea? Please help me. Here is a code, from CFileDialog:

void CMyApp::OnImageOpen() { CFileDialog dlg(TRUE, _T(".bmp"), "mPath", OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY, "Image files (.bmp; .jpg; *.pgm; *.png) |.bmp;.jpg;.pgm;.png |All Files (.)|.*||",NULL); dlg.m_ofn.lpstrTitle = _T("Select Image"); if (dlg.DoModal() == IDOK) { CString path = dlg.GetPathName(); CString mPath = path.Mid(path.GetLength()-9,5); char *FileName = (char *)LPCSTR (path); int len = strlen(FileName); sscanf(FileName+len-9, "%d", &iImage); //sprintf(FileName+len-9, "%05d",iImage+1);

    IplImage *image; 
    image = cvLoadImage(path);
    strcpy(window_name, path);
    cvNamedWindow(window_name,0);
    cvShowImage(window_name, image);
    cvResizeWindow(window_name,800,600);
    cvSetMouseCallback(window_name,my_mouse_callback,(void*) image);
    bool bContinue = true;
    while(bContinue)
    {
        int key = cvWaitKey();

        bContinue = (key != 27);

        switch(key){
        case 0x00220000:

                            // PgDn

                              break;

        case 0x00210000:

                            // PgUp

            break;
        }
    }
click to hide/show revision 2
No.2 Revision

updated 2014-01-08 15:12:52 -0600

berak gravatar image

How to open next/prev image with key pg dn/pg up

Hi everyone, I have a question for you. I do simple application in MFC and OpenCV 2.0 that will perform a 3D reconstruction from several images. Each image represents the same object from different angles, this images are together in some folder, like My Pictures etc. I draw points on each image, that points represent the x,y coordinates that will be used later. When I open image in my application from some folder and select the points, I don't know how to open next image that comes in that folder. If I open the first image and select the points, how to open second image and select points on it, then comes third picture etc. I use switch case function, key pg dn is for next image, pg up is for previous image. Does anyone have an idea? Please help me. Here is a code, from CFileDialog:

void CMyApp::OnImageOpen()
{
CFileDialog dlg(TRUE, _T(".bmp"), _T("*.bmp"), "mPath", OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,
"Image files (.bmp; .jpg; (*.bmp; *.jpg; *.pgm; *.png) |.bmp;.jpg;.pgm;.png |*.bmp;*.jpg;*.pgm;*.png |All Files (.)|.*||",NULL);
(*.*)|*.*||",NULL);
dlg.m_ofn.lpstrTitle = _T("Select Image");
if (dlg.DoModal() == IDOK)
{
CString path = dlg.GetPathName();
CString mPath = path.Mid(path.GetLength()-9,5);
char *FileName = (char *)LPCSTR (path);
int len = strlen(FileName);
sscanf(FileName+len-9, "%d", &iImage);
//sprintf(FileName+len-9, "%05d",iImage+1);

"%05d",iImage+1);
 IplImage *image;
 image = cvLoadImage(path);
  strcpy(window_name, path);
 cvNamedWindow(window_name,0);
  cvShowImage(window_name, image);
 cvResizeWindow(window_name,800,600);
  cvSetMouseCallback(window_name,my_mouse_callback,(void*) image);
 bool bContinue = true;
 while(bContinue)
 {
  int key = cvWaitKey();
  bContinue = (key != 27);
 switch(key){
  case 0x00220000:
 // PgDn
 break;
  case 0x00210000:
 // PgUp
 break;
 }
  }