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

GC fixes #408

Merged
merged 2 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/OpenCvSharp/Cv2/Cv2_cuda.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public static void RegisterPageLocked(Mat m)
if (m == null)
throw new ArgumentNullException(nameof(m));
NativeMethods.cuda_registerPageLocked(m.CvPtr);
GC.KeepAlive(m);
}

/// <summary>
Expand All @@ -126,6 +127,7 @@ public static void UnregisterPageLocked(Mat m)
if (m == null)
throw new ArgumentNullException(nameof(m));
NativeMethods.cuda_unregisterPageLocked(m.CvPtr);
GC.KeepAlive(m);
}

#endregion
Expand All @@ -145,6 +147,7 @@ public static void CreateContinuous(int rows, int cols, MatType type, GpuMat m)
if (m == null)
throw new ArgumentNullException(nameof(m));
NativeMethods.cuda_createContinuous1(rows, cols, type, m.CvPtr);
GC.KeepAlive(m);
}

/// <summary>
Expand Down Expand Up @@ -199,6 +202,7 @@ public static void EnsureSizeIsEnough(int rows, int cols, MatType type, GpuMat m
if (m == null)
throw new ArgumentNullException(nameof(m));
NativeMethods.cuda_ensureSizeIsEnough(rows, cols, type, m.CvPtr);
GC.KeepAlive(m);
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/OpenCvSharp/Cv2/Cv2_highgui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public static void ImShow(string winname, Mat mat)
try
{
NativeMethods.highgui_imshow(winname, mat.CvPtr);
GC.KeepAlive(mat);
}
catch (BadImageFormatException ex)
{
Expand Down
1 change: 1 addition & 0 deletions src/OpenCvSharp/Cv2/Cv2_imgcodecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public static bool ImEncode(string ext, InputArray img, out byte[] buf, int[] pr
using (var bufVec = new VectorOfByte())
{
int ret = NativeMethods.imgcodecs_imencode_vector(ext, img.CvPtr, bufVec.CvPtr, prms, prms.Length);
GC.KeepAlive(img);
buf = bufVec.ToArray();
return ret != 0;
}
Expand Down
16 changes: 0 additions & 16 deletions src/OpenCvSharp/Cv2/Cv2_photo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public static void Inpaint(InputArray src, InputArray inpaintMask,
dst.Fix();
GC.KeepAlive(src);
GC.KeepAlive(inpaintMask);
GC.KeepAlive(dst);
}
#endregion

Expand Down Expand Up @@ -62,7 +61,6 @@ public static void FastNlMeansDenoising(InputArray src, OutputArray dst, float h
NativeMethods.photo_fastNlMeansDenoising(src.CvPtr, dst.CvPtr, h, templateWindowSize, searchWindowSize);
dst.Fix();
GC.KeepAlive(src);
GC.KeepAlive(dst);
}
#endregion
#region FastNlMeansDenoisingColored
Expand Down Expand Up @@ -94,7 +92,6 @@ public static void FastNlMeansDenoisingColored(InputArray src, OutputArray dst,
NativeMethods.photo_fastNlMeansDenoisingColored(src.CvPtr, dst.CvPtr, h, hColor, templateWindowSize, searchWindowSize);
dst.Fix();
GC.KeepAlive(src);
GC.KeepAlive(dst);
}
#endregion
#region FastNlMeansDenoisingMulti
Expand Down Expand Up @@ -128,7 +125,6 @@ public static void FastNlMeansDenoisingMulti(IEnumerable<InputArray> srcImgs, Ou
templateWindowSize, h, templateWindowSize, searchWindowSize);
dst.Fix();
GC.KeepAlive(srcImgs);
GC.KeepAlive(dst);
}
/// <summary>
/// Modification of fastNlMeansDenoising function for images sequence where consequtive images have been captured
Expand Down Expand Up @@ -185,7 +181,6 @@ public static void FastNlMeansDenoisingColoredMulti(IEnumerable<InputArray> srcI
templateWindowSize, h, hColor, templateWindowSize, searchWindowSize);
dst.Fix();
GC.KeepAlive(srcImgs);
GC.KeepAlive(dst);
}
/// <summary>
/// Modification of fastNlMeansDenoisingMulti function for colored images sequences
Expand Down Expand Up @@ -266,8 +261,6 @@ public static void Decolor(
colorBoost.ThrowIfNotReady();
NativeMethods.photo_decolor(src.CvPtr, grayscale.CvPtr, colorBoost.CvPtr);
GC.KeepAlive(src);
GC.KeepAlive(grayscale);
GC.KeepAlive(colorBoost);
grayscale.Fix();
colorBoost.Fix();
}
Expand Down Expand Up @@ -308,7 +301,6 @@ public static void SeamlessClone(
GC.KeepAlive(src);
GC.KeepAlive(dst);
GC.KeepAlive(mask);
GC.KeepAlive(blend);
blend.Fix();
}

Expand Down Expand Up @@ -340,7 +332,6 @@ public static void ColorChange(

GC.KeepAlive(src);
GC.KeepAlive(mask);
GC.KeepAlive(dst);
dst.Fix();
}

Expand Down Expand Up @@ -376,7 +367,6 @@ public static void IlluminationChange(

GC.KeepAlive(src);
GC.KeepAlive(mask);
GC.KeepAlive(dst);
dst.Fix();
}

Expand Down Expand Up @@ -411,7 +401,6 @@ public static void TextureFlattening(

GC.KeepAlive(src);
GC.KeepAlive(mask);
GC.KeepAlive(dst);
dst.Fix();
}

Expand Down Expand Up @@ -441,7 +430,6 @@ public static void EdgePreservingFilter(
src.CvPtr, dst.CvPtr, (int)flags, sigmaS, sigmaR);

GC.KeepAlive(src);
GC.KeepAlive(dst);
dst.Fix();
}

Expand All @@ -468,7 +456,6 @@ public static void DetailEnhance(
src.CvPtr, dst.CvPtr, sigmaS, sigmaR);

GC.KeepAlive(src);
GC.KeepAlive(dst);
dst.Fix();
}

Expand Down Expand Up @@ -500,8 +487,6 @@ public static void PencilSketch(
src.CvPtr, dst1.CvPtr, dst2.CvPtr, sigmaS, sigmaR, shadeFactor);

GC.KeepAlive(src);
GC.KeepAlive(dst1);
GC.KeepAlive(dst2);
dst1.Fix();
dst2.Fix();
}
Expand Down Expand Up @@ -532,7 +517,6 @@ public static void Stylization(
src.CvPtr, dst.CvPtr, sigmaS, sigmaR);

GC.KeepAlive(src);
GC.KeepAlive(dst);
dst.Fix();
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/OpenCvSharp/Cv2/Cv2_video.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static RotatedRect CamShift(

RotatedRect result = NativeMethods.video_CamShift(
probImage.CvPtr, ref window, criteria);
GC.KeepAlive(probImage);
return result;
}

Expand All @@ -42,6 +43,7 @@ public static int MeanShift(

int result = NativeMethods.video_meanShift(
probImage.CvPtr, ref window, criteria);
GC.KeepAlive(probImage);
return result;
}

Expand Down Expand Up @@ -82,7 +84,6 @@ public static int BuildOpticalFlowPyramid(
(int)pyrBorder, (int)derivBorder, tryReuseInputImage ? 1 : 0);
pyramid.Fix();
GC.KeepAlive(img);
GC.KeepAlive(pyramid);
return result;
}

Expand Down Expand Up @@ -120,6 +121,7 @@ public static int BuildOpticalFlowPyramid(
int result = NativeMethods.video_buildOpticalFlowPyramid2(
img.CvPtr, pyramidVec.CvPtr, winSize, maxLevel, withDerivatives ? 1 : 0,
(int) pyrBorder, (int) derivBorder, tryReuseInputImage ? 1 : 0);
GC.KeepAlive(img);
pyramid = pyramidVec.ToArray();
return result;
}
Expand Down Expand Up @@ -174,14 +176,11 @@ public static void CalcOpticalFlowPyrLK(

NativeMethods.video_calcOpticalFlowPyrLK_InputArray(
prevImg.CvPtr, nextImg.CvPtr, prevPts.CvPtr, nextPts.CvPtr,
status.CvPtr, err.CvPtr, winSize0,maxLevel,
status.CvPtr, err.CvPtr, winSize0, maxLevel,
criteria0, (int)flags, minEigThreshold);
GC.KeepAlive(prevImg);
GC.KeepAlive(nextImg);
GC.KeepAlive(prevPts);
GC.KeepAlive(nextPts);
GC.KeepAlive(status);
GC.KeepAlive(err);
nextPts.Fix();
status.Fix();
err.Fix();
Expand Down Expand Up @@ -233,6 +232,8 @@ public static void CalcOpticalFlowPyrLK(
prevImg.CvPtr, nextImg.CvPtr, prevPts, prevPts.Length,
nextPtsVec.CvPtr, statusVec.CvPtr, errVec.CvPtr,
winSize0, maxLevel, criteria0, (int)flags, minEigThreshold);
GC.KeepAlive(prevImg);
GC.KeepAlive(nextImg);
nextPts = nextPtsVec.ToArray();
status = statusVec.ToArray();
err = errVec.ToArray();
Expand Down Expand Up @@ -278,7 +279,6 @@ public static void CalcOpticalFlowFarneback(InputArray prev, InputArray next,
(int)flags);
GC.KeepAlive(prev);
GC.KeepAlive(next);
GC.KeepAlive(flow);
flow.Fix();
}

Expand All @@ -303,6 +303,8 @@ public static Mat EstimateRigidTransform(

IntPtr result = NativeMethods.video_estimateRigidTransform(
src.CvPtr, dst.CvPtr, fullAffine ? 1 : 0);
GC.KeepAlive(src);
GC.KeepAlive(dst);
return new Mat(result);
}

Expand Down
2 changes: 2 additions & 0 deletions src/OpenCvSharp/Modules/aruco/CvAruco.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static void DetectMarkers(InputArray image, Dictionary dictionary, out Po

GC.KeepAlive(image);
GC.KeepAlive(dictionary);
GC.KeepAlive(parameters);
}

/// <summary>
Expand Down Expand Up @@ -81,6 +82,7 @@ public static void DrawDetectedMarkers(InputArray image, Point2f[][] corners, IE
int[] idxArray = EnumerableEx.ToArray(ids);
NativeMethods.aruco_drawDetectedMarkers(image.CvPtr, cornersAddress.Pointer, cornersAddress.Dim1Length, cornersAddress.Dim2Lengths, idxArray, idxArray.Length, borderColor);
}
GC.KeepAlive(image);
}
}

Expand Down
Loading