opencvsharp icon indicating copy to clipboard operation
opencvsharp copied to clipboard

Cannot convert from OpenCvSharp.Point2f[] to OpenCvSharp.Mat<OpenCvSharp.Point2f>

Open Dcruise546 opened this issue 3 years ago • 2 comments

Summary of your issue

Could not find any methods that will let me convert the Point2f[] to Mat<Point2f>

A little background: I am trying to move from OpenCvSharp 3 to OpencvSharp 4. Therefore changing every instance of MatOfPoint2f to Mat<Point2f>.

Environment

Visual Studio 2019 Windows 10 .Net Framework 4.7.2

Example code:

I only pasted the part of the code and please do not care about the approach here! The variable Point2f[] is of my interest here.

List<Mat<Point2f>> imagePoints = new List<Mat<Point2f>>
Point2f[] corners = null;
var foundCorners = Cv2.FindChessboardCorners(
                                calibrationImage,
                                new Size(CalibrationPatternSize.X, CalibrationPatternSize.Y),
                                out corners,
                                ChessboardFlags.AdaptiveThresh);
var subPixelCorners = Cv2.CornerSubPix(calibrationImage, corners, new Size(1, 1), new Size(-1, -1), criteria);
imagePoints.Add(corners.Clone()); // This is where I get the error
corners.Dispose(); // Obviously an error here as well

What did you intend to be?

Either I wish to know a workaround or a simpler way to convert the variable 'corners' to Mat<Point2f> and add it to my list.

Dcruise546 avatar Feb 01 '22 10:02 Dcruise546

Something like this:

var matCorners = new Mat(corners.Length, 1, MatType.CV_32FC2, corners);

No need to dispose corners it's an array of structs.

JoanCharmant avatar Mar 10 '22 10:03 JoanCharmant

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 21 '22 00:09 stale[bot]