2D Shape Detection

asked 2017-10-15 02:35:34 -0600

LLSH gravatar image

updated 2017-10-17 23:01:37 -0600

Hi, I am pretty new to the OpenCV world. I have a school assignment which require me to write a C++ code about 2d shape detection using Fourier Descriptors. The objective of this assignment is to detect the digit “6” in the provided image “a2.bmp” using C++ objective of this assignment is to detect the digit “6” in the provided image “a2.bmp” using C++. 1. Crop out the digit “6” from the top left corner of the image “ a2.bmp”, and store it as template. 2. Detect all the digit “6” in the image “ a2.bmp” by using Fourier Descriptors. I understand the concept for Fourier Descriptors in theory and did all tutorial for opencv. But I still have no idea how to write the source code, maybe so guidance or template for me will help me. Thanks.

edit retag flag offensive close merge delete

Comments

show us, what you tried so far

berak gravatar imageberak ( 2017-10-15 02:39:28 -0600 )edit

Thanks Berak. I have now tried (1) Convert my input image to grey scale (2) Use Canny edge detection to Blur the image, perform thresholding and detect the edge Now I am stuck at how to list the contour in term of pixels and aIso how can I perform differential coding (current coordinate - next coordinate) for contour coordinates and save it as vector of new points. Convert this to two planes (one for x and another for y).

LLSH gravatar imageLLSH ( 2017-10-17 11:17:53 -0600 )edit

ok. after (1) and (2) use findContours(), to get the points, and boundingRect() to get the enclosing box. this will let you crop your template shape, and you can imsave() it.

(the advanced part is ofc. the fourier descriptors..)

berak gravatar imageberak ( 2017-10-18 01:16:58 -0600 )edit

Alright thanks Berak. After this step I will be preforming DFT. How do I calculate Magnitude from result of DFT and trim the high frequency components.

LLSH gravatar imageLLSH ( 2017-10-18 02:41:28 -0600 )edit

assuming, your dft has real output, you have to split it into x and y components, and use magnitude

berak gravatar imageberak ( 2017-10-18 02:51:12 -0600 )edit

hmmm... How about how do I trim the high frequency components after I got the magnitude.

LLSH gravatar imageLLSH ( 2017-10-18 03:18:32 -0600 )edit