I'm trying to compare card bitmaps in an android application.
The error I'm getting is:
OpenCV Error: Assertion failed (H1.type() == H2.type() && H1.type() == CV_32F) in double cv::compareHist(cv::InputArray, cv::InputArray, int), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/histogram.cpp, line 1985Converting the Mat's to CV_32F doesn't seem to fix the problem. Here is my code:
String[] cardFileName= { "c2.jpg","c3.jpg","c4.jpg","c5.jpg","c6.jpg","c7.jpg","c8.jpg","c9.jpg","c10.jpg","cJ.jpg","cQ.jpg","cK.jpg","cA.jpg", "d2.jpg","d3.jpg","d4.jpg","d5.jpg","d6.jpg","d7.jpg","d8.jpg","d9.jpg","d10.jpg","dJ.jpg","dQ.jpg","dK.jpg","dA.jpg", "h2.jpg","h3.jpg","h4.jpg","h5.jpg","h6.jpg","h7.jpg","h8.jpg","h9.jpg","h10.jpg","hJ.jpg","hQ.jpg","hK.jpg","hA.jpg", "s2.jpg","s3.jpg","s4.jpg","s5.jpg","s6.jpg","s7.jpg","s8.jpg","s9.jpg","s10.jpg","sJ.jpg","sQ.jpg","sK.jpg","sA.jpg" }; int[] cardValue = { 2,3,4,5,6,7,8,9,10,11,12,13,1, 2,3,4,5,6,7,8,9,10,11,12,13,1, 2,3,4,5,6,7,8,9,10,11,12,13,1, 2,3,4,5,6,7,8,9,10,11,12,13,1 }; double[] comparisonResults={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; public Bitmap checkCardBitmap; public int DetectCardValue(Bitmap cardBitmap) { for(int cardIndex=0; cardIndex < 52; cardIndex++) { String thisFile=Environment.getExternalStorageDirectory() + "/Android/data/cards/" + cardFileName[cardIndex]; checkCardBitmap = BitmapFactory.decodeFile(thisFile); checkCardBitmap = Bitmap.createScaledBitmap(checkCardBitmap, cardWidth, cardHeight, false); Mat checkCardMat= new Mat(); Mat cardMat= new Mat(); Utils.bitmapToMat(checkCardBitmap, checkCardMat); Utils.bitmapToMat(cardBitmap, cardMat); checkCardMat.convertTo(checkCardMat, CvType.CV_32F); // <--didn't seem to help? cardMat.convertTo(cardMat,CvType.CV_32F); //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// //this line generates the error: double compResult=Imgproc.compareHist(cardMat,checkCardMat,Imgproc.CV_COMP_CORREL); //////////////////////////////////////////////////////////////////////////////////////////// comparisonResults[cardIndex] = compResult; } double max = comparisonResults[0]; int matchedCardIndex=0; for (int i = 0; i < comparisonResults.length; i++) { if (comparisonResults[i] > max) { max = comparisonResults[i]; matchedCardIndex=i; } } return cardValue[matchedCardIndex]; }