Ask Your Question
0

Detecting shapes using opencv with Java

asked 2017-10-19 04:46:11 -0500

ChukZ gravatar image

How can i find straight line, square, circle, polygon, angle, arc, vertical line, inter-circle distance, 4 point angle etc. using opencv and java. How can i start this.Please guide me.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-10-19 08:15:40 -0500

updated 2017-10-19 08:19:01 -0500

You sound rather new to OpenCV in general so these are my recommendations

  1. After you are done with the installation process, proceed to following this tutorial. It should give you a basic idea of the main operations popularly used in OpenCV. I would go through sections Your First Java Application with OpenCV, Your First JavaX Application with OpenCV, OpenCV Basics, Image Segmentation and Object Detection. These sections consist of all the different pre-processing you would be required to do to isolate your objects.

  2. Then look into findContours(); explanation, Java usage.

  3. From that point onwards, it becomes a matter of you performing different operations on the detected contours to see if they meet certain criteria. You could look at the Shape Factor. The area and perimeter can be attained using contourArea() and arcLength() as demonstrated here; I believe Imgproc.contourArea() and Imgproc.arcLength() are the Java equivalent. For circles you are expected to get values very close to 1. For triangles you are going to get low values around 0.3. For squares you are expected to get values around 0.7-0.8.

After you have done all of this and was able to detect a couple things, then you can start looking into Hough Line Transform and Hough Circle to compare the attained results.

Demos: I would look into blob detection and shape detection only after reviewing the OpenCV basics. They do solve a couple of your problems but if you rush into them, you'll have a very hard time understanding what the hell is going on.

Two Cents: As you might have noticed, some of my links consist of Python/C++ material. The API calls are similar so it should not be hard to convert it to Java. I would recommend you get familiar with either languages; in case you currently are not, because a huge chunk of the resources out there are in one of those two languages.

Always refer to the documentation; official, Java version should you get stuck at any point. Plus, Google and StackOverflow have never been a disappointment

After going through all of this, and you are up for the challenge, you can look into more sophisticated method like Hausdorff Distance and Chamfer Matching

Happy coding,

Cheers mate! :)

edit flag offensive delete link more

Comments

Thank you very much @eshirima.

ChukZ gravatar imageChukZ ( 2017-10-19 23:03:58 -0500 )edit

@ChukZ You're welcome. Don't forget to upvote and mark as answer if it helped u.

eshirima gravatar imageeshirima ( 2017-10-20 02:58:39 -0500 )edit

almost two years have passed. something to update ?

how you manage ?

LiorA gravatar imageLiorA ( 2019-04-16 10:19:20 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-10-19 04:46:11 -0500

Seen: 6,610 times

Last updated: Oct 19 '17