Extract Rectangle From Screenshot Using Sample Corners

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Lancaster
Posts: 3
Joined: 2012-07-05T18:01:02-07:00
Authentication code: 13

Extract Rectangle From Screenshot Using Sample Corners

Post by Lancaster »

Hello,
I am currently developing a utility for the PC game Diablo 3. I would like to use IM to extract what are called "item cards" from screenshots taken of the game. Here is an example of a typical screenshot of a user's inventory, with an item card:

Image

The item card is directly next to the mouse cursor in the screenshot. I've viewed the background removal/masking page and I'm a little confused about how best to go about this. There was a similar utility created using very small corner samples from item cards that is no longer functioning, so I think that may be one of the best ways to go about this.

Important details:
  • Item cards vary in height, but never in width
  • Cards will always be within a small radius of the mouse cursor, which never varies in size, shape, or color
  • Screenshots will not be .jpg, I simply converted the above example for ease of uploading
  • Because I am creating this program for a potentially large userbase, the more versatile the trimming method, the better. Slight differences in resolution or gamma settings might produce problems.
Some of Fred's scripts would obviously be very useful here but unfortunately I'm limited to a Windows environment (I am a longtime Linux user but sadly Diablo 3 is only Windows and OS X native). The script I wind up making to do this will probably be in python or another language. Just from the hour or so I've spent browsing the forums I've seen how dedicated and helpful the IM devs are so thank you in advance for any help you can offer. I have a ton of work to do on this program and IM is shaping up to be a big part of it.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Extract Rectangle From Screenshot Using Sample Corners

Post by anthony »

I would break it up into smaller problems for seperate topics.

Starting with 'locating the cursor image' does it appear in the actualy image, or is it provides as a separate coodinate location.
Could the cursor be obscuring part of the desired image?

If you have a image of the cursor, then a sub-image compare, should locate it
http://www.imagemagick.org/Usage/compare/#sub-image

However the "compare" program will not do shaped images. So a morphology or correlation method would probably work better.
http://www.imagemagick.org/Usage/convol ... ate_search


Next step is search near cursor for the identifying marks of what you want.
Actually you may be better just looking for those marks directly rather than the cursor. (see above links)
Could their be multiple matches? What if you don't get a match?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Lancaster
Posts: 3
Joined: 2012-07-05T18:01:02-07:00
Authentication code: 13

Re: Extract Rectangle From Screenshot Using Sample Corners

Post by Lancaster »

The cursor is probably not useful at all. Whatever screenshot utility will most likely have an option to disable it anyway. The exact pixels of the corners of an item card's border should be enough to determine the crop, right? I made two BMP samples of the corners (top left and bottom right) that are 7px by 7px and that should be unique enough to identify the rectangle I want to crop. How can I tell imagemagick to crop using those two samples?

Edit: Will converting the samples and the screenshot to text have something to do with it?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Extract Rectangle From Screenshot Using Sample Corners

Post by anthony »

See the links above!!! The first link should do the job.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Lancaster
Posts: 3
Joined: 2012-07-05T18:01:02-07:00
Authentication code: 13

Re: Extract Rectangle From Screenshot Using Sample Corners

Post by Lancaster »

I get it now, I really should have read more thoroughly. Thanks for you help Anthony! Should I post in here again if I run into further issues or make a new thread?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Extract Rectangle From Screenshot Using Sample Corners

Post by anthony »

if it is the same problem here, for a different aspect or part of the the overall project, perhaps a new thread.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply