Note that there are some explanatory texts on larger screens.

plurals
  1. POresults compareHist in openCV
    primarykey
    data
    text
    <p>I'm trying to compare two histograms which I stored as an array. I'm new with the c++ interface (cv::Mat) and calculating histograms in OpenCV. </p> <p>My code:</p> <pre><code>int testArr1[4] = {12, 10, 11, 11}; int testArr2[4] = {12, 0, 11, 0}; cv::Mat M1 = cv::Mat(1,4,CV_8UC1, testArr1); cv::Mat M2 = cv::Mat(1,4,CV_8UC1, testArr2); int histSize = 4; float range[] = {0, 20}; const float* histRange = {range}; bool uniform = true; bool accumulate = false; cv::Mat a1_hist, a2_hist; cv::calcHist(&amp;M1, 1, 0, cv::Mat(), a1_hist, 1, &amp;histSize, &amp;histRange, uniform, accumulate ); cv::calcHist(&amp;M2, 1, 0, cv::Mat(), a2_hist, 1, &amp;histSize, &amp;histRange, uniform, accumulate ); double compar_c = cv::compareHist(a1_hist, a2_hist, CV_COMP_CORREL); double compar_chi = cv::compareHist(a1_hist, a2_hist, CV_COMP_CHISQR); double compar_bh = cv::compareHist(a1_hist, a2_hist, CV_COMP_BHATTACHARYYA); double compar_i = cv::compareHist(a1_hist, a2_hist, CV_COMP_INTERSECT); cout &lt;&lt; "compare(CV_COMP_CORREL): " &lt;&lt; compar_c &lt;&lt; "\n"; cout &lt;&lt; "compare(CV_COMP_CHISQR): " &lt;&lt; compar_chi &lt;&lt; "\n"; cout &lt;&lt; "compare(CV_COMP_BHATTACHARYYA): " &lt;&lt; compar_bh &lt;&lt; "\n"; cout &lt;&lt; "compare(CV_COMP_INTERSECT): " &lt;&lt; compar_i &lt;&lt; "\n"; </code></pre> <p>The results are a bit unexpected:</p> <pre><code>compare(CV_COMP_CORREL): 1 compare(CV_COMP_CHISQR): 0 compare(CV_COMP_BHATTACHARYYA): 0 compare(CV_COMP_INTERSECT): 4 </code></pre> <p>For intersection, for example, I expected something like 0.5. What am I doing wrong? Can I not put arrays in a cv::mat? Or did I choose the wrong histogram "settings"?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload