Ask Your Question
1

VideoCapture is not working with OpenCV 2.4.3

asked 2013-03-15 19:36:42 -0600

Hamid Bazargani gravatar image

Hi everybody, Recently I migrated to OpenCV 2.4.3 from 2.4.1.

My program which worked well with 2.4.1 version now encounters problem with 2.4.3.

The problem is related to VideoCapture that can not open my video file.

I saw similar problem while searching the net but I couldn't find a proper solution for this. Here is my sample code:

VideoCapture video(argv[1]);
while(video.grab())
{
    video.retrieve(imgFrame);
    imshow("Video",ImgFrame);
    waitKey(1);
}

It's worth mentioning that capturing video from webcam device works well but I want to grab stream from file.

I'm using Qt creator 5 and I compiled OpenCV with MingW. I'm on Windows platform either.

I tried several different video formats and I rebuilt opencv with and without ffmpeg. But the problem is still consistent.

Any idea to solve the problem?

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-03-16 02:42:52 -0600

It is pretty simple, but many don't know the trick. There are two options for windows and visual studio, so guess it will work also on Qt.

  1. Set your project settings to multibyte code.
  2. Change argv[1] to argv[1].c_str()

This should do the trick. Actually you could have seen this by looking at the boolean that is returned when opening a file, by creating the videoreader and the applying the open function.

edit flag offensive delete link more

Comments

Thanks for suggestion. I did the way you said but I get error on " argv[1].c_str() " . I added the line to my project for multibyte char DEFINES += _MBCS

Hamid Bazargani gravatar imageHamid Bazargani ( 2013-03-16 18:31:46 -0600 )edit

Actually I made a little mistake. The following code should actually work.

  • First add the multibyte char option to your project
  • Then store the argument in a string : string temp = argv[1] <-- this needs the multibyte option
  • Then use the string argument for the creation of your video : VideoReader video(temp.c_str())

It works on my pc!

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-17 13:35:52 -0600 )edit

I did the same thing. my specified argument is like : C:\Users\ASUS\my_proj\video.avi But still not working. actually it was working well with OpenCV 2.4.1

Hamid Bazargani gravatar imageHamid Bazargani ( 2013-03-17 13:57:48 -0600 )edit

Could you please add double backslashes, they are used as escape symbols, which just corrupts your path, based on the operating system. So use C:\Users\ASUS\my_proj\video.avi !

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-17 14:34:33 -0600 )edit

I almost tested all possible combinations!

Hamid Bazargani gravatar imageHamid Bazargani ( 2013-03-17 15:18:18 -0600 )edit

Any luck with this? I have tried many ways to open mp4 files without success. My basic code appears correct as it opens avi files.

a_w_baker gravatar imagea_w_baker ( 2013-12-10 08:54:23 -0600 )edit

Question Tools

Stats

Asked: 2013-03-15 19:36:42 -0600

Seen: 2,017 times

Last updated: Mar 16 '13