Skip to content
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

getting black screen only #7

Open
Yusufathi opened this issue Mar 26, 2021 · 10 comments
Open

getting black screen only #7

Yusufathi opened this issue Mar 26, 2021 · 10 comments

Comments

@Yusufathi
Copy link

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 ?

@Abhijith14
Copy link

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 ?

@isinteger
Copy link

Still no fix?

@Abhijith14
Copy link

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.

@GarrettMaury7921
Copy link

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.

@Shikamaru5
Copy link

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.

@Lukkasss
Copy link

Lukkasss commented Nov 27, 2021

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.

@Shikamaru5
Copy link

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!

@Abhijith14
Copy link

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.

@Dirbeq
Copy link

Dirbeq commented Sep 18, 2023

Check this , worked for me

@enonymous1
Copy link

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

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

No branches or pull requests

8 participants