Skip to content

Incorrect Parameter Type for fillConvexPoly #90

Closed
@gilles1977

Description

@gilles1977

Description

The fillConvexPoly wrapper in the react-native-fast-opencv library has an incorrect parameter type for the pts argument. According to the function signature in the library's API, it is defined as:

invoke( name: 'fillConvexPoly', img: Mat, pts: MatVector, color: Scalar, lineType: LineTypes ): void;

However, in the OpenCV C++ API, cv::fillConvexPoly expects an array of points (e.g., std::vectorcv::Point or const cv::Point*) for the pts parameter, not a MatVector (which is typically used for a collection of Mat objects). In the context of react-native-fast-opencv, the pts parameter should likely be a PointVector or a Mat containing points (e.g., N rows, 1 column, 2 channels for x, y coordinates) to align with standard OpenCV usage.

When attempting to create a MatVector from a single Mat with dimensions N x 1 and 2 channels (representing x, y coordinates for N points), the function throws an assertion error in the underlying OpenCV C++ code:

CV_Assert(0 <= i && i < (int)v.size());

Steps to Reproduce

  • Create a Mat with N x 1 dimensions and 2 channels to store polygon points (e.g., 4 points for a rectangle).
  • Create a MatVector and add the Mat to it.
  • Call fillConvexPoly with the MatVector as the pts parameter.
const color = OpenCV.createObject(
  ObjectType.Scalar,
  255, // White color for mask
  255, // White color for mask
  255, // White color for mask
);
// Create a blank image (400x400, 3-channel color)
const img = OpenCV.createObject(
  ObjectType.Mat,
  400,
  400,
  DataTypes.CV_8UC3,
);
const array = [
  [50, 50],
  [150, 50],
  [150, 150],
  [50, 150],
];
// Create a Mat with 4 points (N x 1, 2 channels) for a rectangle
const pointsMat = OpenCV.createObject(
  ObjectType.Mat,
  4,
  1,
  DataTypes.CV_32SC2,
  array.flat(), // Flatten the array to [x0, y0, x1, y1, ..., xN, yN]
);
// Create a MatVector and add the pointsMat
const matVector = OpenCV.createObject(ObjectType.MatVector);
OpenCV.addObjectToVector(matVector, pointsMat);

// Call fillConvexPoly, which throws the assertion error
OpenCV.invoke(
  'fillConvexPoly',
  img,
  matVector,
  color,
  LineTypes.LINE_8,
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions