Jump to content

Reading pixel data from CM with python


Recommended Posts

Hey, I'm looking for advice from some tech-savvy gamer. I'm running a series of weapons effects tests in CMBN that involves repetitive tasks, so I've automated them with a python script. It works, but a big hurdle is the fact is that I don't know how to read pixel data from the screen into memory - PIL.ImageGrab doesn't work in CM any more than a PrintScreen does. I have a workaround - I save a screenshot with Fraps and then read the bmp file, but you can imagine the problems associated with this method. As a minimum, I could speed things up considerably if I could read from the screen directly.

Is there a way to read pixel RGB values from CMBN in python?

I have Windows 10, Python 3.6.3, CMBN 4.0, and no GPU (yes, you read that right - just Intel HD graphics on a laptop; I'm running on minimum graphics settings and the game just works unless too many things detonate at once).

Link to comment
Share on other sites

I'm no python expert but a couple of clues might help you get there. CM renders the screen using open GL. So, if you can get open GL to save the screen using Python you should get what you want.

https://stackoverflow.com/questions/32052271/capture-screen-using-glut-and-opengl-with-python

Of course that speaks to code to capture the screen that program rendered. I am not sure if there is another example that could lead to capturing the screen rendered by another program.

That might get you pointed down a path the gets you what you want.

 

 

Link to comment
Share on other sites

On 28/12/2017 at 12:46 AM, IanL said:

I'm no python expert

Me neither, and I don't know anything about computer graphics :) But in my experience, you can do wonders just by stealing pieces of code from other people and gluing them together. Not this time though, I haven't been able to get the OpenGL library to work with CMBN no matter what, and PIL still captures the desktop under the game rather than the game itself.

Anyway, Fraps will do. It's progressing nicely.

Thanks @IanL, @HerrTom for the help!

Link to comment
Share on other sites

On 31/12/2017 at 2:14 AM, Muzzleflash1990 said:

If you can use a Windows screenshot, then can can get the game into windowed mode. Then even ordinary PrnSc would work.

Do you know a way to run the game in windowed mode? I couldn't find any, and from what I read around here, I thought there wasn't any... I suppose yes, in that case all my "problems" would be solved.

Link to comment
Share on other sites

7 hours ago, Muzzleflash1990 said:

Did find this weird trick. If you ALT-TAB into the game, and PrnScr, it will capture how the game screen was when you entered. So maybe, if you could make it ALT-TAB, out, and then back again, then capture the screen with PIL.ImageGrab?

Interesting (and weird too)... the trick doesn't work for me, even if I alt-tab into the game, the PrintScreen still captures the desktop. But anyway, I need to analyze about 100 screens in each test and I am running thousands of tests, so the game would probably go crazy if I was alt-tabbing in and out every fraction of a second.

Thanks for the tip though!

Link to comment
Share on other sites

7 hours ago, sbobovyc said:

It is not clear to me if you truly need to capture the screen at runtime to do your analysis or if you could just use fraps or any other similar software to capture video and do your analysis offline.

I use fraps as a workaround, the only problem is that it is slow - the file needs to be written to disk first. I estimate there's potential to speed up by a factor of two. But never mind that - I'm about done with the tests and as it turned out, the time needed to actually run the test was not the main bottleneck.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...