justadudewhohacks / justadudewhohacks/opencv4nodejs

Find something strange with Func: drawFillConvexPoly()

Open
#783 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5.1k
Forks
826
PR merge metrics
No merged PRs in 30d

Description

## Background & Problem Description
I am doing Affine Transform in a Triangle Mesh. After that, I create a mask Mat so that I can copy the updated triangular region to the output image further.

> The `mask.drawFillConvexPoly()` helps me determine the triangle area:

```
const cv = require("opencv4nodejs")
let mask = new cv.Mat(100, 99, cv.CV_32FC4)
const points = []
points.push(new cv.Point2(10, 10))
points.push(new cv.Point2(80, 80))
points.push(new cv.Point2(50, 10))
mask.drawFillConvexPoly(points, new cv.Vec(1.0, 1.0, 1.0), 16, 0)
```
If everything is correct (e.g. `let mask = new cv.Mat(100, 100, cv.CV_32FC4)` is just okay) , the mask should be exactly a white triangle with a black background.
expectation
However, in this case, `cv.imshow("mask", mask)` return this:
surprise

> **I wanna know the reason and how to avoid this if this is not a bug.**

## Possibilities
- DataType of mask Mat? : (I tried cv.CV_8UC3 still got this problem)
- DataType of point2? : It seems we do not have point2f & point2i in opencv4nodejs
- cv.imshow(...) not accurate?
- Number of channels?
- points should be inside the Mat: I already avoid this as u can see in my sample code.
...

## What I tried
I tried to print out some data value of pixels in the mask:
```
let maskAsArr = mask.splitChannels()[0].getDataAsArray()
console.log(maskAsArr[30].slice(0, 50))
```
It turns out some values are **negative / extremely large** such as _8388608, -2.3543017412042005e+21, 4.134773263365008e-38_, instead of _**0 or 1**_.
After casting them into 0, most abnormal points disappear:
```
let maskAsArr = mask.splitChannels()[0].getDataAsArray()
.map(function (col) {
col = col.map(function (val) {
if (val != 0 && val != 1) {
val = 0
}
return val
})
return col
})
```

## Environment Info
*OpenCV version* : 4.4.0
*OS*: MacOSX

Contributor guide

Open the contributing guide

Research direction

Reproduce the provided drawFillConvexPoly example with OpenCV 4.4.0, comparing the 100×99 and 100×100 masks and the listed data types. Start at the drawFillConvexPoly binding and inspect the resulting pixel values alongside cv.imshow output; done means identifying whether the behavior is a binding or usage bug and establishing a verified way to avoid it.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
computer-vision
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.