Opencv4nodejs: [ Request ] compareHist sample code

Created on 21 Jan 2018  路  6Comments  路  Source: justadudewhohacks/opencv4nodejs

hi,

can I request a sample code for comparing histogram of two different image?

thanks,

Most helpful comment

So I was able to make it work.
Thanks a lot for awesome work @justadudewhohacks 馃憤

const cv = require('../');

let baseImg = cv.imread('../data/ph-1.jpg').convertTo(cv.CV_32F);
let sampleImg= cv.imread('../data/Lenna.png').convertTo(cv.CV_32F);

let baseHist = cv.calcHist(baseImg, [{channel: 1, ranges: [0, 255], bins: 255}]).convertTo(cv.CV_32F)
let sampleHist = cv.calcHist(sampleImg, [{channel: 1, ranges: [0, 255], bins: 255}]).convertTo(cv.CV_32F)

console.log(sampleHist.compareHist(baseHist, cv.HISTCMP_CORREL)) // 0.03410325814186557

All 6 comments

Hi,

There is an example how to create and plot histograms:
https://github.com/justadudewhohacks/opencv4nodejs/blob/master/examples/plotHist.js

Comparing histograms is done by const val = hist1.compareHist(hist2, method), where method is one of the OpenCV codes for the comparison methods.

I am not quite sure, but I think at the moment opencv4nodejs can only handle up to 3 dimensional histograms.

If that is the case then i'm doing it right, but in electronjs, when I try to compare histogram the renderer process is crashing(white screen) although I successfully plot H1 and H2 using your example code, just the part with H1.compareHist(H2, cv.HISTCMP_CORREL) keeps crashing.

let mat1 = cv.imread('image1.jpg')
const H1= this.calcHist(mat1) // this will return 3d histogram
let mat2 = cv.imread('image2.jpg')
const H2 =this.calcHist(mat2) 

const result = H1.compareHist(H2, cv.HISTCMP_CORREL) // this line keeps on crashing

i'm on windows 10, using opencv 3.4.

Any idea why is this happening?

Crashing without any error message or stacktrace? You can check segfaults via npm segfault handle. But it doesnt work with multithreaded code

_Crashing without any error message or stacktrace?_ __YES__

i will try that, thanks a lot.

So I was able to make it work.
Thanks a lot for awesome work @justadudewhohacks 馃憤

const cv = require('../');

let baseImg = cv.imread('../data/ph-1.jpg').convertTo(cv.CV_32F);
let sampleImg= cv.imread('../data/Lenna.png').convertTo(cv.CV_32F);

let baseHist = cv.calcHist(baseImg, [{channel: 1, ranges: [0, 255], bins: 255}]).convertTo(cv.CV_32F)
let sampleHist = cv.calcHist(sampleImg, [{channel: 1, ranges: [0, 255], bins: 255}]).convertTo(cv.CV_32F)

console.log(sampleHist.compareHist(baseHist, cv.HISTCMP_CORREL)) // 0.03410325814186557

Great!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ShadabFaiz picture ShadabFaiz  路  7Comments

developer239 picture developer239  路  5Comments

YaronHershkovitz picture YaronHershkovitz  路  6Comments

pabx06 picture pabx06  路  4Comments

developer239 picture developer239  路  5Comments