Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mat.setTo() method is not working. And opencv.core.add() does not have enough parameters #738

Closed
Bahramudin opened this issue Jul 5, 2017 · 2 comments

Comments

@Bahramudin
Copy link

I am trying to set the value of the Mat to 255 (white), it throws an exception.

It is the code:

Mat mask = Mat.zeros(frame.size(), CV_8UC1).asMat();
Mat maskSubMat = new Mat(mask, faceRect);
maskSubMat .setTo(new Mat(maskSubMat.size(), maskSubMat.type(), Scalar.WHITE));

The Exception:

OpenCV Error: Assertion failed (checkScalar(value, type(), _value.kind(), _InputArray::MAT )) in cv::Mat::setTo, file C:\projects\bytedeco\javacpp-presets\opencv\cppbuild\windows-x86_64\opencv-3.2.0\modules\core\src\copy.cpp, line 538

This API should not receive a Mat object, it will good to pass a Scalar object, something like this:
mat.setTo(Scalar scalar);

And also the the opencv_core.add() parameters are not enough, it should be something like this:

void add(Mat src, Scalar scalar, Mat result, Mat mask)
// or
void add(Mat src1, Mat src2, Mat result, Mat mask)

It is the original OpenCV API (simple, easy, beautiful and enjoyable)

Mat mask = Mat.zeros(frame.size(), CvType.CV_8UC1);
Mat maskSubMat = mask.submat(faceRect);
maskSubMat.setTo(new Scalar(255));
Core.add(frame, new Scalar(90, 90, 90), frame, mask);
@saudet
Copy link
Member

saudet commented Jul 5, 2017

Try something like this: #684 (comment)

We need to add at least a constructor for Mat that takes a Scalar as single argument...

saudet added a commit to bytedeco/javacpp-presets that referenced this issue Sep 16, 2017
 * Add a `Mat(Scalar)` constructor to OpenCV for convenience (issue bytedeco/javacv#738)
 * Include the `libavutil/time.h` for FFmpeg (issue bytedeco/javacv#735)
@saudet
Copy link
Member

saudet commented Jan 18, 2018

The new convenience constructors are now part of the newly released version 1.4. Enjoy!

@saudet saudet closed this as completed Jan 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants