0

I tried to utilize Open CV and another CCV libraries, both are open source material, but have huge source sizes, whereas my requirement is only to detect rectangular shapes in a larger image and extract them. I am forced to have a very small footprint of my app.

Lets say after loading images of any format (JPEG, PNG etc) in a bitmap array what should be the next move, assuming that rectangles allow little fault tolerance,angle correction, clear boundary line (but not monolithic in its body color) and can be any width/height.

duckduckgo
  • 1,280
  • 1
  • 18
  • 32
  • My project team back in university used openCV for some basic depth perception algorithms in a fairly simple c++ winforms app. It was fairly painless, and IIRC we just imported the whole library and then went from there. – element11 Jul 19 '15 at 05:22
  • are you are saying that you took only relevant portion of code from open cv? actually i like opencv but if i have to import whole code then i will give up – duckduckgo Jul 19 '15 at 05:24
  • 1
    I know for a fact we didnt reduce the library size. After doing some googling i understand that the library size has increased about 10 times in size compared to about 5 years ago when we used it. I apologize but i dont think i will be of much help. We just used the entire library when it was about 30 MB. – element11 Jul 19 '15 at 05:33

1 Answers1

1

If you really don't want to use OpenCV or another Computer Vision Library you can implement the algorithms necessary.

I'm not sure why your binary file would be super large. You'd only need to include the code for imgproc and core (I think, it's been a little while since I've used it).

You'll need to segment your image. Your foreground being the shapes you want to test and the background everything else. This isn't too bad if you know what color they are or what color the background is).

Compute the connected components in your foreground. This will extract pixels forming a blob. (a simple linear pass going from top left to bottom right and bottom right to top left will do this in 2N time).

Once you have the connected components you can compute the 0th 1st and 2nd central image moments for each. https://en.wikipedia.org/wiki/Image_moment is pretty good.

The 0th moment is the area of connected component. First moments are the centroid of the blob. The second moments can tell you the rotation of the object. The Eigen values of the 2nd central moments covariance matrix will be proportional to the major and minor axis of your rectangle.

This will give you the information about your blob. I.E. its location the image and it's rotation.

To determine if that blob is a rectangle there are several methods. You can use a Hough Transform see Rectangle detection with Hough transform

Or you can try to compute the expected compactness (Perimeter / area) of a rectangle with the Given Area and major (length) and minor (width) axis proportionality to the actual compactness of the blob. If it's close enough then you have a rectangle like object. (depending on how close is close enough you may get things that are more oval than rectangular).

While these algorithms aren't particularly hard to implement it may be difficult to get all of them working perfectly together. It may be easier for you to find what parts of OpenCV you need to include in your binary and only include those portions.

Community
  • 1
  • 1
Timothy Murphy
  • 1,322
  • 8
  • 16
  • thanks for "Hough transform" link, i will go through existing libraries, even there an overview of procedure is very helpful – duckduckgo Jul 19 '15 at 06:30
  • No problem. Existing libraries are a great choice as they've been tested much more thoroughly and will most likely be optimized for their given tasks. – Timothy Murphy Jul 19 '15 at 06:37