Thanks for your reply, I think you’re right about that, and it turns out that this was an XY problem.
My actual problem isn’t displaying the image but actually having a Mat that represents the warpAffine in a meaningful way.
Take this example:
List<MatOfPoint> matOfPoints = new List<MatOfPoint>();
Mat hierarchy = new Mat(mat.height(), mat.width(), CvType.CV_8UC3);
// find contours of whole image
Imgproc.findContours(chromaKeyed, matOfPoints, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
// loop each contour
for (int i = 0; i < matOfPoints.Count; i++)
MatOfPoint points = matOfPoints[i];
// create convex hull around piece
MatOfInt hullInt = new MatOfInt();
List<Point> pointMatList = points.toList();
List<int> hullIntList = hullInt.toList();
List<Point> hullPointList = new List<Point>();
for (int j = 0; j < hullInt.toList().Count; j++)
Here I select a specific contour from an image, then generate a convex hull around said contour, the next step is to add each Point along the hull to a list for use later.
Now, my issue is warpAffine’ing that list of Points into something meaningful, so I convert the List to a Mat, and warpAffine it, except the next step is to crop the Mat based on the values that I get back from the warpAffine. See below:
// rotate the hull points
Mat hullPoints = Converters.vector_Point_to_Mat(piece.hullPoints);
Imgproc.warpAffine(hullPoints, hullPoints, rotationMatrix, new Size(hullPoints.width(), hullPoints.height()));
// find bounding rect with new hull points
OpenCVForUnity.CoreModule.Rect rect = Imgproc.boundingRect(hullPoints);
Imgproc.rectangle(hullPoints, rect, new Scalar(255, 255, 255, 255));
Mat croppedHullPoints = new Mat(hullPoints, rect);
Except that I get an error on the cropping part with this error message:
Mat::n_1Mat__JIIII() : OpenCV(4.6.0-dev) C:\Users\satoo\Desktop\opencv\modules\core\src\matrix.cpp:767: error: (-215:Assertion failed) 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows in function ‘cv::Mat::Mat’
Which looks to be caused by an oversized Rect, but I got the points for the Rect from the hullPoints, so how is that possible?
Well, after investigation, the image produced after converting the points to a Mat is this:
(it’s a solid white line, hard to see on this background)
Which is nothing like what the points are supposed to represent:
(can’t upload a second image, it’s a square shape with a convex hull surrounding it, basically nothing like the first image)
This is presumably a problem with going from CV_8UC3 to CV_32SC2, no?
I think this is a problem with Converters.vector_Point_to_Mat(), is that the correct method to use?