1

I'm currently trying to identify a character based on an 8 bit matrix which I've extracted around a tag as part of my program (I've called this matrix "tag_character" and an example image of the "D" character is below).

enter image description here

Because I need classification to be invariant to rotation, I had PCA recommended as a potential technique, however I'm having a little difficulty with how to use it. The working code is below:

cv::Mat image_row = tag_character.clone ( ).reshape ( 1, 1 );
image_row.convertTo( image_row, CV_32F );
cv::Mat projection_result;
cv::PCA pca ( image_row, cv::Mat ( ), CV_PCA_DATA_AS_ROW );
pca.project ( image_row, projection_result );
cv::Point pos = cv::Point(pca.mean.at<double>(0, 0), pca.mean.at<double>(0, 1));

So now that I have the position, I'm not sure how I can use this to actually uniquely identify each tag. By the way, I'm looping over each contour and then classifying them, so the PCA is being run separately for each tag.

Jack Simpson
  • 1,681
  • 3
  • 30
  • 54
  • could you explain, how the 1st 2 mean values make a *position* ? (imho, they're still pixel values, not location). also, if at all, you want to store double values in a Point2d or Point2f, not a Point (integer truncation) – berak Oct 13 '14 at 07:35
  • Hi Berak, to be honest I'm hoping someone can help make me sense of that part of the code as well - I don't really understand what the point actually means in this context (this code is what I could piece together from all the websites & books I could find about PCA in OpenCV). Thanks for the advice about using Point2f :) – Jack Simpson Oct 13 '14 at 07:48
  • ah, that explains the other weirdness in your code: taking the pca of a *single* image row. imho, you should make a pca of *all* your train-images, then later project your test-image to pca space, and find the closest item from the similar projected train-images. – berak Oct 13 '14 at 07:53
  • I kind of deliberately have only created a single row image to run the PCR on because my program is designed to track and attempt to identify the tag when I can see enough of it - so I'm hoping I can perform a PCA analysis for each tag as part of the tracking system. If this is possible, I'm hoping I can do this, otherwise I'll restructure my main program if the only way to do PCA is to do it for multiple rows. My main logic is that in any given frame, I probably won't have all the tags visible anyway so I couldn't perform a PCA for every tag in the system anyway. – Jack Simpson Oct 13 '14 at 08:00

0 Answers0