0

I have 32 alphabet cards like OSMO application (https://www.playosmo.com/en/words/).
I wanna recognize them in image or real time in frams of a camera and I want this app for android device
so I used opencv and c++ for this purpose.
the methods that I tried are

  • first I used sift and surf and orb for getting keyPoints and compare them with a static picture of card
  • second method was the k nearest neighbor.I train some picture and make two xml files which one of them contain the pixels of all train image in binary mode and the ohter one is a classification file which was a map for trained image.

first method had a problem which was the keypoints can change in real time and are not unique. so matching the keypoints is not good.
second method problem was that xml file loading was too long in android device.
so now I need help
is there any fast reliable method? what can I do?

Rostami
  • 141
  • 1
  • 4
  • Is [tesseract](https://www.learnopencv.com/deep-learning-based-text-recognition-ocr-using-tesseract-and-opencv/) available for you? – Yunus Temurlenk Jan 30 '20 at 11:39
  • No, I did not use that because in examples it was not precise in real time application. – Rostami Jan 31 '20 at 18:23
  • 1
    Did you try to save contours of those letters or numbers as an array and then use matchshape function to find those contours in big image. This can give high speed also good results by supporting alşso with other opencv functions – Yunus Temurlenk Feb 04 '20 at 13:52
  • yes I am working on this. thank you for recommendation. – Rostami Feb 06 '20 at 11:25
  • 1
    If you have some problems about these steps, you can ask a new question, and I may help you. Good luck!!! – Yunus Temurlenk Feb 06 '20 at 11:27

1 Answers1

0

finally I found a way to detect letters in may cards
for recognize the letters in the cards I use Hu moments
which is some thing like matching the Shape but it is more accurate
https://www.learnopencv.com/shape-matching-using-hu-moments-c-python/
below code retrun a double which is the different between two image
so I use the different and compare it with other image and then recognize the letter in the image.

double HuMatchingShape(double*  secondMoments,double* firstMoments)
{
    double dif = 0;
    int counter = 0;
    for (int i = 0; i < 7; i++)
    {
        dif += (firstMoments[i] - secondMoments[i]) * (firstMoments[i] -secondMoments[i]);
    }
    return sqrt(dif);
}

double* getHuMoments(Mat img)
{
    Moments moments = cv::moments(img,true);

    // Calculate Hu Moments
    double * huMoments =  new double[7];

    HuMoments(moments, huMoments);
    for (int i = 0; i < 7; i++)
    {
        huMoments[i] = -1 * copysign(1.0, huMoments[i]) * log10(abs(huMoments[i]));
    }

    return huMoments;
}

int main()
{
   Mat image1 = imread("image path");
   Mat image2 =  imread("second image path");
   // make these two images binary 
   image1 = makeItBinay(image1);
   image2 = makeItBinay(image2);
   // calculate different between two image with hu moments 
   double different = HuMatchingShape(getHuMoments(image1), getHuMoments(image2));
   return 0;
}
Rostami
  • 141
  • 1
  • 4