1

I'm using CImg and Imagemagick and what I'm trying to do is to write a code in which the program gets the image, searches for particular shapes in it (rectangles or triangles for example), then crops each shape and finally saves them as some other png files. Assuming I want the number plate of the yellow car get cropped into a new png file, : enter image description here

(https://www.mediafire.com/view/vs8f32o9gv3x8rp/carnum-1-min.png)

what should I do? And btw, is there a better way to create images (with ImageMagick) giving RGB values? Right now I'm trying this:

image.draw_point()

I was just wondering if there was a better command rather than this (better in any possible way, because I've read a lot of people's comments and compliments about how great and useful ImageMagick commands are.) Thanks.

mitrafrz
  • 51
  • 6
  • Please try to be more specific. What do the images look like? Is there a background? Is it solid or textured? Do the shapes have a fixed or variable size? Can the shapes be rotated? Are the shapes 2-d or 3-d? Are the shapes textured? What OS are you using? – Mark Setchell Feb 21 '18 at 18:41
  • I was trying to attach the image, but I couldn't, so here we go, no there's not a solid background, and the rectangle itself is not just filled with a solid color, it also has some text in it (you could imagine a road sign or something). I didn't quite get the __fixed or variable size__ part, but I guess the answer would be "fixed size", because it's one image (for now of course, in next levels there are gonna be some other images taken from the same object, but from different distances, and the program has to find that specific object in those images too.) – mitrafrz Feb 21 '18 at 19:10
  • You have over 10 points now, so you can add images. – Mark Setchell Feb 21 '18 at 19:12
  • And yes, the shape can be rotated, again, __for now__, it's a 2D shape (again you can imagine road signs), yes I already said the shape contains text, and I'm using windows 10 – mitrafrz Feb 21 '18 at 19:25
  • Please add some sample pictures and answer my other questions when you can. – Mark Setchell Feb 21 '18 at 19:48
  • I just did my best to attach that image I don't know what's wrong with it, so I also uploaded it on mediafire and added the url. And sorry did I miss any of your questions? – mitrafrz Feb 21 '18 at 20:01
  • @MarkSetchell what happened.. – mitrafrz Feb 24 '18 at 16:48
  • Not sure what you mean. The problem as now described is probably best tackled with OpenCV rather than ImageMagick as suggested by Eric (@emcconville). – Mark Setchell Feb 24 '18 at 21:42

1 Answers1

2

... is there a better way to create images (with ImageMagick) giving RGB values?

The method Magick::Image.read supports creating an image from arbitrary pixel data. You'll be responsible for defining the size, channels, and data-storage size.

/* A 3x3 white RGB image */
const unsigned char data[27] = {
    0xff, 0xff, 0xff,    0xff, 0xff, 0xff,    0xff, 0xff, 0xff,
    0xff, 0xff, 0xff,    0xff, 0xff, 0xff,    0xff, 0xff, 0xff,
    0xff, 0xff, 0xff,    0xff, 0xff, 0xff,    0xff, 0xff, 0xff
};
Magick::Image canvas;
canvas.read(
            3, // Width
            3, // Height
            "RGB", // Channels
            Magick::CharPixel, // Storage
            data // pointer to data blob
);

For feature / edge detection, you can use Magick::Image.cannyEdge or Magick::Image.houghLine methods. However, ImageMagick performs raster transformations & manipulation - not contour (object) analysis.

Sounds like you need a tool closer to , specifically contour matching.

emcconville
  • 23,800
  • 4
  • 50
  • 66