codeboost / opencv-node

Use OpenCV with node.js
54 stars 9 forks source link

cv.split #1

Open morgangiraud opened 11 years ago

morgangiraud commented 11 years ago

Hello, i've been trying to follow that opencv tutorials : http://docs.opencv.org/doc/tutorials/imgproc/histograms/histogram_calculation/histogram_calculation.html which should give me some nice histograms plot but, by just following the exact same steps, i couldn't achieve it.

I'm not exactly sure how the binding work for the calcHist function but at least it seems that cv.split(Mat, []) is not filling the array.

Can you have a look on this ?

codeboost commented 11 years ago

Did you try this: var a = [] cv.split(Mat, a); ?

morgangiraud commented 11 years ago

here is the code i used : (coffee)

########################### cv = require 'opencv-node'

src = cv.imread '../test.jpg', 1 console.log src.channels # output 3

plane = [] cv.split src, plane console.log plane # output []

setTimeout () -> console.log plane # output [] , 3000 ###########################

Also, i can't use "console.log Mat", it always crash. D'ont know if it is linked.

codeboost commented 11 years ago

Yes, that was a bug in opencv-node. Actually, I've somehow used an older, unfinished version of the code to publish opencv-node so it had more issues.

Now I've updated opencv-node to version 0.2.3, use

npm update -g opencv-node

to update.

If you look in the scripts directory, there's a effects.coffee which does some effects on running video. Let me know if it works.

codeboost commented 11 years ago

Also, console.log Mat works without crashing now, but doing this would output a looong array of bytes which is not very interesting. For debug purposes, I suggest you write your own logMat() function, which would look something like this:

logMat = (mat) -> console.log "#{mat.wdith}x#{mat.height}x#{mat.type}"
morgangiraud commented 11 years ago

Great, everything works for console.log and cv.split. Thanks for the fix !

Now trying to get something out of cv.calcHist function.

Here is my code: ################################### cv = require 'opencv-node'

src = cv.imread '../test.jpg', 1 histSize = 256 range = {start:0, end:256} uniform = true accumulate = true b_hist = new cv.Mat console.log b_hist.rows #output 0 mask = new cv.Mat planes = []

planes = cv.split src console.log planes[0].rows #output 471 !

cv.calcHist planes[0], 1, 0, mask, b_hist, 1, histSize, range, uniform, accumulate console.log b_hist.rows #output 0 ######################################

The result should be in b_hist but just like with split before, the matrix doesn't change. Probably the same problem as the split function had.

Last question, is it possible to keep the original definition of the function split ? (i mean cv.split mat, array instead of array cv.split mat ?)

codeboost commented 11 years ago

Ahh.. you're hitting where it hurts. Seems like calcHist, calcBackProject and 3 other functions are not ported. I did this thing like 2 years ago and I've forgotten about it. But let me see what I can do. Maybe someone else also needs them ;).

Re: split -> I'll try.

morgangiraud commented 11 years ago

Thanks a lot !