justadudewhohacks / justadudewhohacks/opencv4nodejs
Cannot use CV_16U with equalizeHist()
- Dominant language
- C++
- Stars
- 5.1k
- Forks
- 826
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to get more color depth by going 16bit with my mat before equalizing and though docs indicate 16U and 32U should work, I get the following crash when passing that 16U mat to `.equalizeHist()`.
```bash
OpenCV(3.4.1) Error: Assertion failed (_src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3))) in equalizeHist, file /opencv/opencv-3.4.1/modules/imgproc/src/histogram.cpp, line 3914
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.1) /opencv/opencv-3.4.1/modules/imgproc/src/histogram.cpp:3914: error: (-215) _src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3)) in function equalizeHist
Aborted
```
```js
// EXAMPLE USE
// mat = equalize( mat, cv.COLOR_BGR2Lab, cv.COLOR_Lab2BGR, 0 )
// mat = equalize( mat, cv.COLOR_BGR2YCrCb, cv.COLOR_YCrCb2BGR, 0 )
// This crashes on the .equalizeHist() call
function equalize16U( mat, convertInt, convertBack, eqChannel ) {
if ( mat.channels >= 3 ) {
let c = mat.convertTo( cv.CV_16U ).cvtColor( convertInt ).split();
c[ eqChannel ] = c[ eqChannel ].equalizeHist();
return new cv.Mat( [ c[0], c[1], c[2] ] ).cvtColor( convertBack ).convertTo( cv.CV_8U ); // new cv.Mat( [ [], [], [] ] is equiv to .merge( [], [], [] ) )
} else {
return mat;
}
}
// This works, but in 8bit, I get artifacts I'd rather not have
function equalize( mat, convertInt, convertBack, eqChannel ) {
if ( mat.channels >= 3 ) {
let c = mat.cvtColor( convertInt ).split();
c[ eqChannel ] = c[ eqChannel ].equalizeHist();
return new cv.Mat( [ c[0], c[1], c[2] ] ).cvtColor( convertBack ); // new cv.Mat( [ [], [], [] ] is equiv to .merge( [], [], [] ) )
} else {
return mat;
}
}
```
Contributor guide
Research direction
Reproduce the JavaScript example with a CV_16U matrix, then inspect OpenCV's modules/imgproc/src/histogram.cpp around line 3914 and the equalizeHist entry point. Compare the reported type assertion with the relevant OpenCV documentation. Done means the CV_16U behavior is clearly established and the issue has an actionable resolution or documented limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100