Skip to content

VideoCapture does not work. OpenCV 3.2.0 #8677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nhlsm opened this issue Apr 30, 2017 · 15 comments
Closed

VideoCapture does not work. OpenCV 3.2.0 #8677

nhlsm opened this issue Apr 30, 2017 · 15 comments
Labels

Comments

@nhlsm
Copy link
Contributor

nhlsm commented Apr 30, 2017

System information (version)
  • OpenCV => 3.2.0
  • Operating System / Platform => Windows 10 64 bit
  • Compiler => Visual Studio 2015 32bit
Detailed description

VideoCapture does not work. OpenCV 3.2.0. ( just black screen )
I check outed from https://github.com/opencv/opencv.git/tags/opencv-3.2.0 and build with MSVC 2015

debug print say that...

SETUP: Setting up device 0
SETUP: WebCam SC-13HDL11624N
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 640x480
SETUP: trying specified format RGB24 @ 640x480
SETUP: trying format RGB24 @ 640x480
SETUP: trying format RGB32 @ 640x480
SETUP: trying format RGB555 @ 640x480
SETUP: trying format RGB565 @ 640x480
SETUP: trying format YUY2 @ 640x480
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.

Event: Code: 0x0d Params: 0, 0
Event: Code: 0x0e Params: 0, 0
Event: Code: 0x03 Params: -2147024891, 0
  • code desc
    0x0d : EC_CLOCK_CHANGED
    0x03 : EC_ERRORABORT, -2147024891(0x80070005)
    0x0e : EC_PAUSED

cap_dshow.cpp, 2315 line, bool videoInput::isDeviceDisconnected(int deviceNumber)
It is added function on opencv 3.2.0.

Steps to reproduce
VideoCapture cap(0);
assert(cap.isOpen());
while(1)
{
	Mat frame;
	cap >> frame; 
	imshow("cap", frame); 
        // black screen
	waitKey(10);
}
@wuzhenwu
Copy link

wuzhenwu commented May 1, 2017

i have the same environment as u. u can try the code below fisrt, it works on my machine.
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap;
if (argc > 1)
cap.open(argv[1]);
else
cap.open(0);

if (!cap.isOpened())
{
	std::cerr << "Cannot read video. Try moving video file to sample directory." << std::endl;
	return -1;
}

namedWindow("FG Segmentation", WINDOW_NORMAL);

Mat frame,segm;
for (;;)
{
	cap >> frame;
	if (frame.empty())
		break;
	frame.copyTo(segm);

	imshow("FG Segmentation", segm);


	int c = waitKey(30);
	if (c == 'q' || c == 'Q' || (c & 255) == 27)
		break;
}


return 0;

}

@nhlsm
Copy link
Contributor Author

nhlsm commented May 1, 2017

Thank you for reply, wuzhenwu. But, it does not work.

The log message is as follows. Can you upload your log meesge on yout machine?
( The debug built binary can print log message. )

I suspect "Event: Code: 0x03 Params: -2147024891, 0"
Code 0x03 means EC_ERRORABORT.

***** VIDEOINPUT LIBRARY - 0.1995 - TFW07 *****

SETUP: Setting up device 0
SETUP: WebCam SC-13HDL11624N
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 640x480
SETUP: trying specified format RGB24 @ 640x480
SETUP: trying format RGB24 @ 640x480
SETUP: trying format RGB32 @ 640x480
SETUP: trying format RGB555 @ 640x480
SETUP: trying format RGB565 @ 640x480
SETUP: trying format YUY2 @ 640x480
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.

Event: Code: 0x0d Params: 0, 0
Event: Code: 0x03 Params: -2147024891, 0
Event: Code: 0x0e Params: 0, 0

@wuzhenwu
Copy link

wuzhenwu commented May 2, 2017

here is my debug info. I think what u suspected is right. u can dig into the problem,or maybe
u can try a new camera first if possible.
***** VIDEOINPUT LIBRARY - 0.1995 - TFW07 *****

SETUP: Setting up device 0
SETUP: USB2.0 PC CAMERA
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 640x480
SETUP: trying specified format RGB24 @ 640x480
SETUP: trying format RGB24 @ 640x480
SETUP: trying format RGB32 @ 640x480
SETUP: trying format RGB555 @ 640x480
SETUP: trying format RGB565 @ 640x480
SETUP: trying format YUY2 @ 640x480

SETUP: Capture callback set
SETUP: Device is setup and ready to capture.

Event: Code: 0x0d Params: 0, 0
Event: Code: 0x0e Params: 0, 0

@nhlsm
Copy link
Contributor Author

nhlsm commented May 2, 2017

Thank you for reply, wuzhenwu.
Another camera does not work. ( same, just black screen )

  1. Both camera work fine with AMCAP (9.20) program.
  2. Both camera does not work with old AMCAP ( < 9.20 )
    ( error message is "bla bla bla ... 80070005." 80070005 is -2147024891 in decimal )

@mshabunin mshabunin added the bug label May 3, 2017
@Techkid86
Copy link

Same problem. Code that worked only a few days ago does not work now after a forced update (windows 10)
same -2147024891 Event code parameters. Even after uninstalling the updates manually, the problem remains. Either windows changed something in the registry somewhere, or the updates are not contained to what "Programs and Features" can uninstall. Additionally, my cameras (both built in and external logitech C270) work when accessed by skype, but crash when accessed by a program called GRIP. GRIP complains that "CameraService Crashed".
GRIP is an openCV integrated program written in java

edu.wpi.grip.core.sources.GrabberService$GrabberServiceException: [Webcam 0] Failed to grab image
    at edu.wpi.grip.core.sources.GrabberService.runOneGrab(GrabberService.java:75)
    at edu.wpi.grip.core.sources.GrabberService.run(GrabberService.java:64)
    at com.google.common.util.concurrent.AbstractExecutionThreadService$1$2.run(AbstractExecutionThreadService.java:66)
    at com.google.common.util.concurrent.Callables$4.run(Callables.java:122)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.bytedeco.javacv.FrameGrabber$Exception: videoInput.getPixels() Error: Could not get pixels.
    at org.bytedeco.javacv.VideoInputFrameGrabber.grab(VideoInputFrameGrabber.java:171)
    at edu.wpi.grip.core.sources.GrabberService.runOneGrab(GrabberService.java:73)
    ... 4 more

crashes with this stacktrace. Hope this helps.

@joel92217
Copy link

I have the same problem. This problem may be caused by Windows Update. Uninstall Windows update KB3150513 solves my problem. For your reference.

@Techkid86
Copy link

I had uninstalled the most recent windows updates, restarted, and it remained inoperable. only recently (yesterday) did it start working again. Maybe it needed several restarts? I also added the registry fix that helped when windows 10 anniversary update had broken webcams, as well as turned off the permissions for "Apps" to use the webcam. From what I could find, that event code is a lack of permission for webcam access. It was certainly a windows problem, but idk what solved the issue for me.

@nhlsm
Copy link
Contributor Author

nhlsm commented May 11, 2017

Thank you for reply, Techkid86.
It works!!!

My case,

  1. open Settings -> Privacy -> Camera
  2. Camera On -> Off -> On
  3. and then it works.

But, I don't know whether it is exact solution or not.

@Bhanudutta
Copy link
Contributor

Bhanudutta commented Oct 5, 2017

Hello Everybody,

I am Also facing a similar issue,

System Information

  • OpenCV => 3.3.0 dev
  • Operating System / Platform => Windows 8.1 64 bit
  • Compiler => MingW gcc C++ 4.8.1 32 bit

Video Capture is not working but just showing black screen ,
Web cam is working smoothly in other applications
as well as working nicely with OpenCV pre-build python and Java binaries , and also older version i.e before OpenCV2 version is also working nicely.
Also the Light of Web Cam is working.

The Binaries are build with Cmake 3.9.0 rc-5 and MingW gcc C++ 4.8.1 32 bit with default configuration except I turned off WITH_PRECOMPILED_HEADER.

Code I am using is same as @nhlsm

I have tried above solution but does't work

@shin127
Copy link

shin127 commented Apr 20, 2019

I had similar issue. and solved it.
I changed opencv 3.6 with python3 to opencv2.4 with python2.7 to solve.

I had black screen with a USB web camera although Other USB web camera work well.
I think some compatibility with opencv code and hardware cause.

I tried above solution of nhslm, privacy setting. But it doesnot work.

in window 10

@rohitrehantx
Copy link

did anyone find a solution to this problem? I am using OpenCV v4.1.2. The camera is locked by python but no frame is displayed when using imshow(frame).

@blakebjorn
Copy link

Please post code samples - it's likely unrelated to this issue (which was fixed within a week from a windows update) if you are getting a lock on the device.

The correct syntax is imshow('window name', frame) and nothing will be shown if you aren't following it with a cv2.waitKey(10) call to render the window.

@rohitrehantx
Copy link

This is my code

import cv2 as cv
import numpy as np
import datetime
import time

cap = cv.VideoCapture(0)
while True:
    ret, frame = cap.read()

    cx = int(cap.get(cv.CAP_PROP_FRAME_WIDTH)/2)
    cy = int(cap.get(cv.CAP_PROP_FRAME_HEIGHT)/2)

    rect = cv.rectangle(frame, (cx-cy,0), (cx+cy,cy+cy), (0, 255, 255), 1)
    line = cv.circle(frame, (cx,cy), cy, (255, 0, 0), 1)

    font = cv.FONT_HERSHEY_SIMPLEX

    dt = str(datetime.datetime.now())

    text = cv.putText(frame, dt, (10,50), font, 1, (0,255,255), 2,cv.LINE_AA)

    #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    #i=i+1
    name = "{}{}".format('frame', 0)
    cv.imshow(name,frame)

    if cv.waitKey(1) & 0xFF == 27:
        break

cap.release()
cv.destroyAllWindows()

@kanagasabapathik
Copy link

waitkey is the answer. welldone bro

@Bhavyashri
Copy link

How did u changed opencv version? @shin127 can you please guide me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests