Skip to content

Commit 0ec8e93

Browse files
author
Florin
committed
calcHist runs without crashing, but not quite yet done
1 parent 3cd4898 commit 0ec8e93

5 files changed

Lines changed: 28 additions & 24 deletions

File tree

bea/constants.bea

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@
345345
FONT_HERSHEY_SCRIPT_COMPLEX
346346
FONT_ITALIC
347347

348-
348+
CV_FILLED
349349

350350

351351

bea/cv.bea

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
void cornerHarris(const Mat& src, Mat& dst, int blockSize, int apertureSize, double k, int borderType=BORDER_DEFAULT)
295295
void cornerEigenValsAndVecs(const Mat& src, Mat& dst, int blockSize, int apertureSize, int borderType=BORDER_DEFAULT)
296296

297-
void calcHist(std::vector<cv::Mat> arrays, std::vector<int> channels, const Mat& mask, cv::SparseMat& hist, int dims, std::vector<int> histSize, std::vector<std::vector<float> > ranges, bool uniform = true, bool accumulate = false)
297+
void calcHist(std::vector<cv::Mat> arrays, std::vector<int> channels, const Mat& mask, cv::Mat& hist, int dims, std::vector<int> histSize, std::vector<std::vector<float> > ranges, bool uniform = true, bool accumulate = false)
298298
#@orgapi void calcHist(const Mat* arrays, int narrays, const int* channels, const Mat& mask, SparseMat& hist, int dims, const int* histSize, const float** ranges, bool uniform=true, bool accumulate=false)
299299
@call
300300

@@ -314,11 +314,11 @@
314314
}
315315
cv::calcBackProject(&arrays[0], arrays.size(), &channels[0], *hist, *backProject, (const float**)&vrangs[0], scale, uniform);
316316

317-
minMaxLocRet minMaxLoc(const SparseMat& a);
318-
#@orgapi void minMaxLoc(const SparseMat& a, double* minVal, double* maxVal, int* minIdx=0, int* maxIdx=0 )
317+
minMaxLocRet minMaxLoc(const Mat& a);
318+
#@orgapi void minMaxLoc(const Mat& a, double* minVal, double* maxVal, int* minIdx=0, int* maxIdx=0 )
319319
@call
320320
minMaxLocRet fnRetVal;
321-
cv::minMaxLoc(*a, &fnRetVal.minVal, &fnRetVal.maxVal, &fnRetVal.minIdx, &fnRetVal.maxIdx);
321+
cv::minMaxLoc(*a, &fnRetVal.minVal, &fnRetVal.maxVal, NULL, NULL);
322322

323323
@manual void cvSmooth(const Mat& src, Mat& dst, int smoothtype=CV_GAUSSIAN, int param1=3, int param2=0, double param3=0, double param4=0)
324324

scripts/calcHist.coffee

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22
#http://opencv.willowgarage.com/documentation/cpp/imgproc_histograms.html?highlight=calchist#calcHist
33
cv = require './opencv'
44
keypress = require 'keypress'
5+
path = require 'path'
56

6-
src = cv.imread "test.jpg", 1
7+
fullpath = path.resolve 'lena.jpg'
8+
9+
console.log 'Opening ', fullpath
10+
src = cv.imread fullpath, 1
711
return console.log 'Error opening file' if src.empty
812

13+
console.log src.size
14+
15+
cv.namedWindow "org", 0
16+
cv.imshow "org", src
17+
918

1019
hsv = new cv.Mat
1120
cv.cvtColor src, hsv, cv.CV_BGR2HSV
@@ -35,24 +44,20 @@ console.log hist.rows + 'x' + hist.cols
3544

3645
minMax = cv.minMaxLoc hist
3746

38-
tmp = new Mat
47+
tmp = new cv.Mat
3948
scale = 10
4049

4150
histImg = tmp.zeros sbins * scale, hbins * 10, cv.CV_8UC3
4251

43-
console.log 'Looping...'
4452
for h in [0..hbins - 1]
4553
for s in [0..sbins - 1]
4654
binVal = hist.at h, s
4755

48-
intensity = Math.round(binVal * 255 / maxVal)
49-
cv.rectangle histImg, {x: h*scale, y: s*scale}, {x: (h+1)*scale - 1, y: (s+1)*scale - 1}, [255, 0, 0], cv.CV_FILLED
56+
intensity = Math.round(binVal * 255 / minMax.maxVal)
57+
cv.rectangle histImg, {x: h*scale, y: s*scale}, {x: (h+1)*scale - 1, y: (s+1)*scale - 1}, [255, 0, 0, 0], -1
5058

51-
namedWindow "source", 1
52-
imshow "source", src
53-
54-
namedWindow "H-S Histogram", 1
55-
imshow "H-S Histogram", histImg
59+
cv.namedWindow "H-S Histogram", 1
60+
cv.imshow "H-S Histogram", histImg
5661

5762
keypress process.stdin
5863
process.stdin.on 'keypress', (char, key) ->
@@ -62,4 +67,5 @@ process.stdin.on 'keypress', (char, key) ->
6267

6368
process.stdin.setRawMode true
6469
process.stdin.resume()
65-
console.log 'Press ESC to stop.'
70+
console.log 'Press ESC to stop.'
71+

src/opencv_manual.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ using namespace cv;
99

1010
namespace opencvjs {
1111

12-
13-
1412
v8::Handle<v8::Value> JMat::at(const v8::Arguments& args) {
1513
METHOD_BEGIN(1);
1614
//Experimental - not tested

src/opencvjs.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,11 +3064,11 @@ namespace opencvjs {
30643064

30653065
v8::Handle<v8::Value> JOpenCV::calcHist(const v8::Arguments& args) {
30663066
METHOD_BEGIN(7);
3067-
//void calcHist(std::vector<cv::Mat> arrays, std::vector<int> channels, const Mat& mask, cv::SparseMat& hist, int dims, std::vector<int> histSize, std::vector<std::vector<float> > ranges, bool uniform = true, bool accumulate = false)
3067+
//void calcHist(std::vector<cv::Mat> arrays, std::vector<int> channels, const Mat& mask, cv::Mat& hist, int dims, std::vector<int> histSize, std::vector<std::vector<float> > ranges, bool uniform = true, bool accumulate = false)
30683068
std::vector<cv::Mat> arrays = bea::Convert<std::vector<cv::Mat> >::FromJS(args[0], 0);
30693069
std::vector<int> channels = bea::Convert<std::vector<int> >::FromJS(args[1], 1);
30703070
cv::Mat* mask = bea::Convert<cv::Mat*>::FromJS(args[2], 2);
3071-
cv::SparseMat* hist = bea::Convert<cv::SparseMat*>::FromJS(args[3], 3);
3071+
cv::Mat* hist = bea::Convert<cv::Mat*>::FromJS(args[3], 3);
30723072
int dims = bea::Convert<int>::FromJS(args[4], 4);
30733073
std::vector<int> histSize = bea::Convert<std::vector<int> >::FromJS(args[5], 5);
30743074
std::vector<std::vector<float> > ranges = bea::Convert<std::vector<std::vector<float> > >::FromJS(args[6], 6);
@@ -3085,11 +3085,11 @@ namespace opencvjs {
30853085
}
30863086

30873087
v8::Handle<v8::Value> JOpenCV::minMaxLoc(const v8::Arguments& args) {
3088-
METHOD_BEGIN(1);
3089-
//minMaxLocRet minMaxLoc(const SparseMat& a)
3090-
cv::SparseMat* a = bea::Convert<cv::SparseMat*>::FromJS(args[0], 0);
3088+
METHOD_BEGIN(1);
3089+
//minMaxLocRet minMaxLoc(const Mat& a)
3090+
cv::Mat* a = bea::Convert<cv::Mat*>::FromJS(args[0], 0);
30913091
minMaxLocRet fnRetVal;
3092-
cv::minMaxLoc(*a, &fnRetVal.minVal, &fnRetVal.maxVal, &fnRetVal.minIdx, &fnRetVal.maxIdx);
3092+
cv::minMaxLoc(*a, &fnRetVal.minVal, &fnRetVal.maxVal, NULL, NULL);
30933093

30943094
return bea::Convert<cv::minMaxLocRet>::ToJS(fnRetVal);
30953095
METHOD_END();

0 commit comments

Comments
 (0)