opencv_tutorials icon indicating copy to clipboard operation
opencv_tutorials copied to clipboard

getting black screen only

Open Yusufathi opened this issue 3 years ago • 10 comments

so i used the code from vid #4 and when i run it with Albion Online Client it shows only a black screen . when i use other screens like paints it works perfectly . any got that issue ?

Yusufathi avatar Mar 26 '21 17:03 Yusufathi

Same here. When I try any tab in Google Chrome, it gives black screen.

image

I am working on google-dino automation. But because of this issue, I am not able to get the screen. So I had to change the windowcapture.py a little bit.

image

changing the raise Exception('Window not found: {}'.format(window_name)) to capture the whole Desktop self.hwnd = win32gui.GetDesktopWindow()

This temporarily solves my issue. But It would have been better if I could get the specific window. Any better solutions to my issue ?

Abhijith14 avatar Jun 26 '21 08:06 Abhijith14

Still no fix?

isinteger avatar Jul 30 '21 18:07 isinteger

No. I am literally checking every possible method to find a solution. If i try to capture the whole window; my fps goes down to 5 - 10.

Abhijith14 avatar Jul 30 '21 18:07 Abhijith14

Did anyone find a solution? For me, my screen is black but it is capturing the right screen, just not rendering. It works for applications like Task Manager but for the game I want it to capture it goes black.

GarrettMaury7921 avatar Nov 23 '21 00:11 GarrettMaury7921

I'm having the same issues with the black screen I think, for awhile it was working fine, and I've tried implementing the code from the other tutorials but the issue has something to do with it copying the screenshots and not getting rid of them. When I don't specify the name of the window it shows me the desktop screen and just spams out screenshots one over the other very quickly. It even still does real time object detection but for some reason I can't find the bug that is making it do this, because as far as I can tell, the windowcapture.py and vision.py are exactly the same as the tutorials. The main.py isn't but the only real changes are the name of the game window, the jpg file, and the way to put rectangles around the specific object. Making it so that I don't use vision makes it speed up just, it doesn't change the outcome. I've also tried what was suggested above, where you get rid of the raise exception for compatiblebitmap but that flat out didn't work, it made the problem worse. If maybe there was a way to delete the previous screenshots so that at all times there was only one I think that might do it but I haven't figured out that code yet. So all in all while I try to figure this out, if anyone has suggestions that would be super wizard, thanks.

Shikamaru5 avatar Nov 26 '21 22:11 Shikamaru5

I had the same issue and what I could find is that chrome uses hardware acceleration features, when you have it turned on, the API can't access the image generated by your videocard. Try disabiling 'Use hardware acceleration when possible' from the chrome menu: Configuration -> Advanced Settings -> System. It should work.

Lukkasss avatar Nov 27 '21 17:11 Lukkasss

Thank you!! It worked just like said it would, I was surprised how easy of a fix disabling and then relaunching that acceleration in Google Chrome was!

Shikamaru5 avatar Nov 27 '21 18:11 Shikamaru5

I had the same issue and what I could find is that chrome uses hardware acceleration features, when you have it turned on, the API can't access the image generated by your videocard. Try disabiling 'Use hardware acceleration when possible' from the chrome menu: Configuration -> Advanced Settings -> System. It should work.

Thanks Alott!!. It worked perfectly.

Abhijith14 avatar Dec 05 '21 06:12 Abhijith14

Check this , worked for me

Dirbeq avatar Sep 18 '23 12:09 Dirbeq

Was also following the "LearnCodeByGaming" guide. I adapted the windowcapture.py to support the capture of the "black" window. Seems to have something to do with hardware accelerated windows? VIA the previous link... Plop the following code as another function in windowcapture.py and call this function instead of the get_screenshot() function as defined in run().

def capture_win_alt(self):
    
    windll.user32.SetProcessDPIAware()

    # get the window image data
    wDC = win32gui.GetWindowDC(self.hwnd)
    dcObj = win32ui.CreateDCFromHandle(wDC)
    cDC = dcObj.CreateCompatibleDC()
    dataBitMap = win32ui.CreateBitmap()
    dataBitMap.CreateCompatibleBitmap(dcObj, self.w, self.h)
    cDC.SelectObject(dataBitMap)

    # If Special K is running, this number is 3. If not, 1
    result = windll.user32.PrintWindow(self.hwnd, cDC.GetSafeHdc(), 3)

    bmpinfo = dataBitMap.GetInfo()
    bmpstr = dataBitMap.GetBitmapBits(True)

    img = np.frombuffer(bmpstr, dtype=np.uint8).reshape((bmpinfo["bmHeight"], bmpinfo["bmWidth"], 4))
    img = np.ascontiguousarray(img)[..., :-1]  # make image C_CONTIGUOUS and drop alpha channel

    if not result:  # result should be 1
        win32gui.DeleteObject(dataBitMap.GetHandle())
        cDC.DeleteDC()
        dcObj.DeleteDC()
        win32gui.ReleaseDC(self.hwnd, wDC)
        raise RuntimeError(f"Unable to acquire screenshot! Result: {result}")

    return img

enonymous1 avatar Nov 15 '23 01:11 enonymous1