Ask Your Question
0

Issue with compareHist function

asked 2019-10-02 11:41:50 -0600

MrAlbum gravatar image

updated 2019-10-02 21:37:53 -0600

supra56 gravatar image

When I calculating the chi-square distance between 2 histograms in Python 3.7.4 with OpenCV 4.1.2, I use the following code:

 dis = cv2.compareHist(hist1, hist2, cv2.HISTCMP_CHISQR)

When I debugging this, there will be a warning which says 'Expected Ptr<cv::umat> for argument '%s'. It seems like the problem is on the 'method' arguement. And I also try to set the method arguement to 1, or method = 1, still the same problem. Can you talented people here help me figure this problem out, please. And I will be great thank to you guys, love you! Thank you very much!

edit retag flag offensive close merge delete

Comments

1

can you show some more code ? what are hist1, hist2 ?

berak gravatar imageberak ( 2019-10-02 12:27:54 -0600 )edit

Snipped:

retval, bestLabels, centers = cv2.kmeans(dsc, K, None, term_crit, 10, 0)
    hist = np.histogram(bestLabels)

hist1 and hist2 generate by np.histogram funtion, inputs kmean of sift descripters of images.

MrAlbum gravatar imageMrAlbum ( 2019-10-02 12:33:21 -0600 )edit

what is e.g. hist1.dtype ? (compareHist() expects floats)

berak gravatar imageberak ( 2019-10-03 03:58:47 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-10-03 04:39:23 -0600

berak gravatar image

updated 2019-10-03 06:55:04 -0600

the failure is already in your numpy code: np.histogram() returns a tuple, you have to use it like:

hist, edges = np.histogram(data)

(you're passing the whole (hist,edges) tuple into compareHist())

next, numpy's histograms are int64, so you will need to convert them to float32 before you can compare those

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-10-02 11:41:50 -0600

Seen: 682 times

Last updated: Oct 03 '19