Ask Your Question

Revision history [back]

Grayscale avi to image

Hi :) I would like to convert a grayscale avi to images. I use the following code but the produced images are all black. When I use a colour avi, it does work perfect but it doesn't work for grayscale avi. How can I solve this problem? Thanks for your help. Best; Beldachi


int main (int argc, char **argv) { if (argc !=2) { std::cout << "USE: " << argv[0] << " <video-filename>" << std::endl; return -1; }

//Open the video that you pass from the command line cv::VideoCapture cap(argv[1]); if (!cap.isOpened()) { std::cerr << "ERROR: Could not open video " << argv[1] << std::endl; return -1; }

int frame_count = 0; bool should_stop = false;

while(!should_stop) { cv::Mat frame; cap >> frame; //get a new frame from the video if (frame.empty()) { should_stop = true; //we arrived to the end of the video continue; }

char filename[128];
sprintf(filename, "frame_%06d.jpg", frame_count);  
frame.convertTo(frame,CV_8U); 
cv::imwrite(filename, frame);
frame_count++;

}

return 0; }

click to hide/show revision 2
No.2 Revision

updated 2013-09-25 04:22:09 -0600

berak gravatar image

Grayscale avi to image

Hi :) I would like to convert a grayscale avi to images. I use the following code but the produced images are all black. When I use a colour avi, it does work perfect but it doesn't work for grayscale avi. How can I solve this problem? Thanks for your help. Best; Beldachi


int main (int argc, char **argv)
{
if (argc !=2)
{
std::cout << "USE: " << argv[0] << " <video-filename>" << std::endl;
return -1;
}

} //Open the video that you pass from the command line cv::VideoCapture cap(argv[1]); if (!cap.isOpened()) { std::cerr << "ERROR: Could not open video " << argv[1] << std::endl; return -1; }

} int frame_count = 0; bool should_stop = false;

false; while(!should_stop) { cv::Mat frame; cap >> frame; //get a new frame from the video if (frame.empty()) { should_stop = true; //we arrived to the end of the video continue; }

}
char filename[128];
 sprintf(filename, "frame_%06d.jpg", frame_count);
 frame.convertTo(frame,CV_8U);
 cv::imwrite(filename, frame);
 frame_count++;
 }
return 0;
}

}

return 0; }

click to hide/show revision 3
No.3 Revision

Grayscale avi to image

Hi :) I would like to convert a grayscale avi to images. I use the following code but the produced images are all black. When I use a colour avi, it does work perfect but it doesn't work for grayscale avi. How can I solve this problem? Thanks for your help. Best; Beldachi


int main (int argc, char **argv)
{
   if (argc !=2)
   { 
    std::cout << "USE: " << argv[0] << " <video-filename>" << std::endl;
    return -1;
   }

  //Open the video that you pass from the command line
  cv::VideoCapture cap(argv[1]);
  if (!cap.isOpened())
  {
    std::cerr << "ERROR: Could not open video " << argv[1] << std::endl;
    return -1;
  }

  int frame_count = 0;
  bool should_stop = false;

  while(!should_stop)
  {
     cv::Mat frame;
     cap >> frame; //get a new frame from the video
     if (frame.empty())
     {
       should_stop = true; //we arrived to the end of the video
       continue;
    }

 }

      char filename[128];
     sprintf(filename, "frame_%06d.jpg", frame_count);  
     frame.convertTo(frame,CV_8U); 
     cv::imwrite(filename, frame);
     frame_count++;
  }

 }

 return 0;
}