OpenCV show video file
Hi, my IDE is QT Creator 5.7.0, compiling with MSVC (2015). I use the OpenCV 3.4.0 My OS is Windows 7 (64 Bit)
When i try to capture and "imshow" the .avi -Video, there is popping up only a gray Window and when the Video is ending, it Shows the last Picture of the Video.
Is it a Problem with opencv_ffmpeg340_64.dll? I still tried to set the Path-Variables, to copy the .dll into the debug Folder, etc.
// Auswahl Video
cv::VideoCapture cap("Regen_02_400fps_K3Stellung_170Belichtung.avi");
// Meldung wenn Video nicht gefunden wird
if (!cap.isOpened())
std::cout<<"Error when reading steam";
//cv::namedWindow("Original");
for(;;)
{
cap.read(frame);
// Abbruch wenn kein Frame mehr gefunden wird
if (!cap.read(frame))
break;
cv::imshow("Original", frame);
cv::waitKey(25);
// Abfolge "Geschwindigkeit" mit WaitKey
char key = cvWaitKey(50);
// ESC drücken um zu unterbrechen
if (key == 27)
break;
}
You repeat each operation twice. You repeat each operation twice ;)
You read the frame twice (so you'll lose every second frame) and capture the keypress twice (so it might not be read.
Try this:
First of all, thanks for your reply. But it hasn´t solved my Problem :(
I changed to...
It still open a Window which is filled gray, only the last Frame of the Video is shown. These are the last lines of the application Output:
Frame 6979 Frame 6980 Frame 6981 Frame 6982 Frame 6983 End of video Unexpected list type. Expected: Isn´t it a Problem with the opencv_ffmpeg340_64.dll, that it probably can´t decode my Video?
Try to read only one frame (without the
while
loop) or read the frames one by one after keypress (key=cv::waitKey()
). Is it still the same gray image? Try debug by displaying the value of a given pixel (std::cout<<frame.at<Vec3b>(10,10)<<std::endl;
) Is it constant?If the images are correctly read, I suspect some kind of threading issue (OpenCV cannot display the images for some reason while decoding the video...)
Again thanks for reply. I tried applied both your advices, unfortunatelly without success.
// if(key==27) break; } std::cout << "End of video" << std::endl;
These are the last lines auf application Output: Frame 6981 230 Frame 6982 229 Frame 6983 230 End of Video
The Pixel values are realistic, the Video is at (10,10) nearly complete White (grayscale Video). There must be any Problem to Display the Video. If i open a single picture, it works to display that. But I am not abe to zoom into the Window, to see the single Pixel values. What could be the Problem?
So, a Little update: I deleted the opencv 3.4.0 and switched to 2.4.13. Now i´´m able to Display my Video with the following code:
The only Thing is, that i´m not able to zoom into the window, to see the Pixel values. Whats wrong there?
Can you get the window toolbar if you create the window using:
(the syntax might differ for OpenCV 2.4). If it doesn't display the toolbar (with the zoom buttons) you ight need to rebuild it using the WITH_QT flag.
It doesn´t work. What do you mean by rebuildung with WITH_QT?
Yes. These functions require QT support, and OpenCV needs to be rebuilt if it doesn't have this. See the highgui documentation for QT functions