Ask Your Question

imshow shows black screen

asked 2016-02-08 01:37:42 -0500

Croolman gravatar image

updated 2016-02-08 02:55:53 -0500

I did create a project where everything was running as intended. Then I reinstalled my system, copied the project and I get black screen when showing any frame of proccessed video. My simple code:

#include <cstdio>
#include "opencv2/opencv.hpp"
#include <iostream>
#include <sstream>

using namespace cv;
using namespace std;

int main(int, char**)
VideoCapture cap("videofile.avi"); 
if (!cap.isOpened())  // check if we succeeded
return -1;

namedWindow("Frame", 1);
for (;;)
    Mat frame;
    if (! {
        cerr << "Unable to read next frame." << endl;
        cerr << "Exiting..." << endl;

    imshow("Frame", frame);
    if (waitKey(30) >= 0) break;

return 0;

The output I am getting: imshow output

I have installed all possible codecs I. Even the FFMPEG which I didn't need last time I was running the project.

There's also this log in console which has never been there before

***** VIDEOINPUT LIBRARY - 0.1995 - TFW07 *****
edit retag flag offensive close merge delete


please ask your question here .

berak gravatar imageberak ( 2016-02-08 01:49:58 -0500 )edit

I have edited the question

Croolman gravatar imageCroolman ( 2016-02-08 02:02:37 -0500 )edit

things you could try:

  • debug it
  • add some info code before the imshow(), like cerr << frame.size() << endl; cerr << frame(Rect(60,60,20,20)) << endl
  • save your image to disc, using imwrite() (at least you know, it's not the capture)
  • as a last resort, rebuild your opencv libs (&project) on your current system
berak gravatar imageberak ( 2016-02-08 03:04:34 -0500 )edit
  • tried to debug, nothing seems out of order (dunno what to look for anyway)
  • it prints the size of the frame, the second command prints zeores only
  • I've saved the imgae - it is black
  • Tried to compile my own libraries, nothing has changed
Croolman gravatar imageCroolman ( 2016-02-08 08:19:55 -0500 )edit

If your saved image is black, then it has something to do with your capture interface.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-09 07:53:20 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-02-09 08:31:33 -0500

Croolman gravatar image

updated 2016-02-10 04:24:19 -0500

EDIT: bin folder of OpenCv was missing in PATH variable. After adding new entry - %OPENCV_DIR%\bin, everything is working propelly.

Clumsy solution - copying 3 dlls into wrking folder

  • opencv_ffmpeg300.dll, opencv_ffmpeg.dll ,openh264-1.5.0-win64msvc.dll
edit flag offensive delete link more


Then your system is basically wrongly configured, since it cannot find the right dlls on its own. What you are doing now is far from an elegant solution...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-10 02:45:17 -0500 )edit

I am well aware of that, but can't come up with better solution. Before reinstalling the system I didn't need to do that.

Croolman gravatar imageCroolman ( 2016-02-10 02:52:22 -0500 )edit

Are you sure that the OPENCV environment variable is set correctly and that your project is linking all the right libraries?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-10 03:04:34 -0500 )edit

Yes, I am. I've done it before and it worked, Don't know why it isn't working now. For example opencv_ffmpeg300.dll is in bin folder of OpenCv path... as guide at says, OPENCV_DIR points to ....x86/vc12 (depending on enviroment) vc12 folder contains lib and bin folder and lib folder next contains the libraries you specify in project (opencv_world300.dll, opencv_ts300.dll and their debug versions).

Croolman gravatar imageCroolman ( 2016-02-10 03:39:08 -0500 )edit

Allright, sometimes things has to be written down to actually click inside the head... So I added bin folder of OpenCv into the path and everythings working fine.

Croolman gravatar imageCroolman ( 2016-02-10 03:44:40 -0500 )edit

I don't think you need openh264-1.5.0-win64msvc.dll but openh264-1.4.0-win64msvc.dll

LBerger gravatar imageLBerger ( 2016-02-10 03:53:42 -0500 )edit

@LBerger, adding dlls explicitly is about the worst thing someone could do ... like being said, his mistake was to wrongly configure his paths!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-10 04:32:13 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-02-08 01:37:42 -0500

Seen: 1,984 times

Last updated: Feb 10 '16