简体   繁体   中英

How can I process an image?

I'm building a program to convert an image file (whatever file type would be easiest) to G-Code for use on a rep-rap with a pen plotter attachment.

I'm wondering if i wanted to process the image pixel by pixel and check things like pixel color, how could I do this with C++?

I would really like to know how I can process a bitmap image, pixel by pixel, to check the color of the pixel.

The best way is to use a library, like for example Magick++ .

When you load an image, you can access it's pixels data with Blob

You will probably want to use an existing library that has been tested.

But for fun/practice/etc, this would be a good exercise and wouldn't be impossible to do. The Bitmap Format is (relatively) simple compared with other image formats. The Wikipedia page has some tons of info, including some C++ code. It looks like once you've gotten past the header information, you get to a pixel array that shouldn't be difficult to parse.

Good luck.

Most image formats consist of a header and the actual raw image data. A bimpap image is no different. If you don't want to use one of the existing libraries, or if you are not allowed to, you should read about bitmap format :

http://en.wikipedia.org/wiki/BMP_file_format

Once you understand this you could create appropriate structs/classes to store the information you want from the header such as x,y size, bpp etc. And also have a pointer to the raw image data. You could then simpy iterate through every pixel and do whatever you want with it :)

Once you decipher the image file, I suggest you place the pixels into a matrix, for the first pass. (Future revisions can use other methods to access the pixels).

You can apply transformations to the pixels by using matrix multiplication. You can also access the pixels individually by using array indexing.

Search the web and SO for "introduction to graphics c++".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM