I have three sides of an object, when I use PCA to extract orientation of the object I found major difficulties like the first and the second image give me the angle in the same quadrant being different sides and the third one being the totally different side. My question is how can I differentiate them based on their pixel composition so that I can run my robotic arm and pick the objects accurately. I don’t want to remove PCA from this as it gives me the best visualization of angles of my object.
there’s matchShapes
that works on contours. I’ve never used it though and the docs on it are poor and if you need more information out of that procedure, you might have to submit a pull request.
or try moments
or HuMoments
. that’ll let you calculate a centroid, the major axis, and probably also which way the wide and narrow end go.
or you can see about implementing some procedure from a commercial machine vision package. they’re specialized to this type of task, while nobody seems to need this in OpenCV badly enough to expend the effort…
How did you compute the gradients for the PCA?
The kernel for the gradients and the PCA analysis window should be at the scale of the object. If you use a sobel filter, it will give you the local orientations (which change at every bend). To get a global orientation, use a Laplacian filter or gaussian derivate and a larger analysis window.
Showing your code would help to understand what you are doing exactly.
why are you asking for gradients? why should principal component analysis involve a window?
Ah, ok, I see.
I prefer to use PCA on the gradients to get the structure tensor, which is a more robust solution - I was thinking OP was trying to achieve this.