Skip to content

Commit

Permalink
Merge pull request #1678 from shimat/fix_mat_ctor
Browse files Browse the repository at this point in the history
Add [Obsolete] to Mat ctor
  • Loading branch information
shimat authored Jun 16, 2024
2 parents 6db152a + 92f89e3 commit 728293a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion samples
Submodule samples updated 64 files
+1 −1 CameraOpenCV/CameraOpenCV.csproj
+2 −2 SamplesCore.Windows/SamplesCore.Windows.csproj
+2 −4 SamplesCore/Program.cs
+45 −45 SamplesCore/Samples/ArucoSample.cs
+23 −23 SamplesCore/Samples/BRISKSample.cs
+16 −16 SamplesCore/Samples/BgSubtractorMOG.cs
+25 −25 SamplesCore/Samples/BinarizerSample.cs
+34 −35 SamplesCore/Samples/CaffeSample.cs
+21 −22 SamplesCore/Samples/CameraCaptureSample.cs
+17 −17 SamplesCore/Samples/ClaheSample.cs
+27 −27 SamplesCore/Samples/ConnectedComponentsSample.cs
+72 −72 SamplesCore/Samples/DFT.cs
+9 −9 SamplesCore/Samples/DnnSuperresSample.cs
+29 −29 SamplesCore/Samples/DrawBestMatch.cs
+13 −13 SamplesCore/Samples/FASTSample.cs
+28 −28 SamplesCore/Samples/FREAKSample.cs
+35 −35 SamplesCore/Samples/FaceDetection.cs
+22 −24 SamplesCore/Samples/FaceDetectionDNN.cs
+32 −33 SamplesCore/Samples/FlannSample.cs
+30 −30 SamplesCore/Samples/HOGSample.cs
+3 −4 SamplesCore/Samples/HandPose.cs
+56 −55 SamplesCore/Samples/HistSample.cs
+62 −61 SamplesCore/Samples/HoughLinesSample.cs
+70 −70 SamplesCore/Samples/InpaintSample.cs
+24 −24 SamplesCore/Samples/KAZESample.cs
+149 −149 SamplesCore/Samples/KAZESample2.cs
+73 −74 SamplesCore/Samples/MDS.cs
+20 −20 SamplesCore/Samples/MSERSample.cs
+61 −61 SamplesCore/Samples/MatOperations.cs
+45 −45 SamplesCore/Samples/MergeSplitSample.cs
+18 −18 SamplesCore/Samples/MorphologySample.cs
+81 −81 SamplesCore/Samples/NormalArrayOperations.cs
+83 −83 SamplesCore/Samples/OpenVinoFaceDetection.cs
+17 −17 SamplesCore/Samples/PerspectiveTransformSample.cs
+22 −22 SamplesCore/Samples/PhotoMethods.cs
+46 −46 SamplesCore/Samples/PixelAccess.cs
+57 −58 SamplesCore/Samples/Pose.cs
+92 −93 SamplesCore/Samples/SVMSample.cs
+94 −93 SamplesCore/Samples/SiftSurfSample.cs
+50 −50 SamplesCore/Samples/SimpleBlobDetectorSample.cs
+29 −30 SamplesCore/Samples/SolveEquation.cs
+23 −23 SamplesCore/Samples/StarDetectorSample.cs
+39 −40 SamplesCore/Samples/Stitching.cs
+41 −42 SamplesCore/Samples/Subdiv2DSample.cs
+23 −24 SamplesCore/Samples/SuperResolutionSample.cs
+68 −67 SamplesCore/Samples/VideoWriterSample.cs
+33 −33 SamplesCore/Samples/WatershedSample.cs
+2 −2 SamplesCore/SamplesCore.csproj
+5 −6 SamplesLegacy/Samples/FaceDetectionDNN.cs
+3 −3 SamplesLegacy/Samples/HandPose.cs
+5 −5 SamplesLegacy/Samples/KAZESample2.cs
+6 −6 SamplesLegacy/Samples/MDS.cs
+2 −2 SamplesLegacy/Samples/MorphologySample.cs
+9 −9 SamplesLegacy/Samples/OpenVinoFaceDetection.cs
+4 −4 SamplesLegacy/Samples/Pose.cs
+3 −3 SamplesLegacy/Samples/SVMSample.cs
+5 −5 SamplesLegacy/Samples/SolveEquation.cs
+3 −3 SamplesLegacy/SamplesLegacy.csproj
+2 −2 SamplesLegacy/packages.config
+2 −2 SamplesVB/SamplesVB.vbproj
+5 −5 VideoCaptureForm/VideoCaptureForm.csproj
+4 −4 VideoCaptureForm/packages.config
+2 −2 VideoCaptureWPF/VideoCaptureWPF.csproj
+0 −15 nuget.config
24 changes: 22 additions & 2 deletions src/OpenCvSharp/Modules/core/Mat/Mat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,27 @@ public Mat(Mat m, Rect roi)
/// The external data is not automatically de-allocated, so you should take care of it.</param>
/// <param name="step">Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any.
/// If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize() .</param>
public static Mat FromPixelData(int rows, int cols, MatType type, nint data, long step = 0)
[Obsolete("Use Mat.FromPixelData instead. This constructor has been deprecated because the introduction of 'nint' made overload resolution confusing.", true)]
public Mat(int rows, int cols, MatType type, IntPtr data, long step = 0)
{
NativeMethods.HandleException(
NativeMethods.core_Mat_new8(rows, cols, type, data, new IntPtr(step), out ptr));
}

/// <summary>
/// constructor for matrix headers pointing to user-allocated data
/// </summary>
/// <param name="rows">Number of rows in a 2D array.</param>
/// <param name="cols">Number of columns in a 2D array.</param>
/// <param name="type">Array type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices,
/// or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.</param>
/// <param name="data">Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data.
/// Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied.
/// This operation is very efficient and can be used to process external data using OpenCV functions.
/// The external data is not automatically de-allocated, so you should take care of it.</param>
/// <param name="step">Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any.
/// If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize() .</param>
public static Mat FromPixelData(int rows, int cols, MatType type, IntPtr data, long step = 0)
{
NativeMethods.HandleException(
NativeMethods.core_Mat_new8(rows, cols, type, data, new IntPtr(step), out var ptr));
Expand Down Expand Up @@ -312,7 +332,7 @@ protected Mat(int rows, int cols, MatType type, Array data, long step = 0)
/// <param name="step">Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any.
/// If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize() .</param>
public static Mat FromPixelData(int rows, int cols, MatType type, Array data, long step = 0)
=> new Mat(rows, cols, type, data, step);
=> new (rows, cols, type, data, step);

/// <summary>
/// constructor for matrix headers pointing to user-allocated data
Expand Down
18 changes: 17 additions & 1 deletion src/OpenCvSharp/Modules/core/Mat/MatOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,23 @@ public static Mat<TElem> FromPixelData(int rows, int cols, IntPtr data, long ste
/// The external data is not automatically de-allocated, so you should take care of it.</param>
/// <param name="step">Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any.
/// If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize() .</param>
public Mat(int rows, int cols, Array data, long step = 0)
#pragma warning disable CA1000
public static Mat<TElem> FromPixelData(int rows, int cols, Array data, long step = 0)
#pragma warning restore CA1000
=> new (rows, cols, data, step);

/// <summary>
/// constructor for matrix headers pointing to user-allocated data
/// </summary>
/// <param name="rows">Number of rows in a 2D array.</param>
/// <param name="cols">Number of columns in a 2D array.</param>
/// <param name="data">Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data.
/// Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied.
/// This operation is very efficient and can be used to process external data using OpenCV functions.
/// The external data is not automatically de-allocated, so you should take care of it.</param>
/// <param name="step">Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any.
/// If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize() .</param>
protected Mat(int rows, int cols, Array data, long step = 0)
: base(rows, cols, GetMatType(), data, step)
{
}
Expand Down

0 comments on commit 728293a

Please sign in to comment.