Fixed memory leak on cvFindContours

Signed-off-by: Laentir Valetov <laex@bk.ru>
This commit is contained in:
Laentir Valetov 2014-10-06 23:26:18 +04:00
parent f61ded0271
commit fe2351f5da
18 changed files with 21 additions and 1 deletions

View File

@ -66,6 +66,7 @@ begin
// cvAdaptiveThreshold(img_gray, img_gray, 255, CV_ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY, 21, 7);
cvShowImage('Threshold image', dst);
contours := AllocMem(SizeOf(TCvSeq));
cvClearMemStorage(storage);
cvFindContours(dst, storage, @contours, SizeOf(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
cvDrawContours(image, contours, CV_RGB(100, 200, 0), CV_RGB(200, 100, 0), 2, 2, CV_AA, cvPoint(0, 0));
cvShowImage('Contour image', image);

View File

@ -160,6 +160,7 @@ begin
cvConvert(img32f, img32s);
// cvFindContours(img32s, storage, @contours, SizeOf(TCvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
cvClearMemStorage(storage);
cvFindContours(img, storage, @contours, SizeOf(TCvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
attrs[0] := 'recursive';

View File

@ -70,6 +70,7 @@ begin
cvThreshold(img_gray, dst, 128, 255, CV_THRESH_BINARY_INV);
// cvAdaptiveThreshold(img_gray, img_gray, 255, CV_ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY, 21, 7);
contours := nil; // AllocMem(SizeOf(TCvSeq));
cvClearMemStorage(storage);
cvFindContours(dst, storage, @contours, SizeOf(TCvContour), CV_RETR_EXTERNAL, // Òîëüêî âíåøíèå êîíòóðû
// CV_RETR_CCOMP, //Âñå êîíòóðû ñ ðàçäåëåíèåì âíåøíèå è äûðêè
CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));

View File

@ -122,6 +122,7 @@ begin
storage := cvCreateMemStorage(0);
// Íàõîäèì êîíòóðû
cvClearMemStorage(storage);
contoursCont := cvFindContours(binI, storage, @contoursI, sizeof(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE,
cvPoint(0, 0));
@ -146,6 +147,7 @@ begin
cvConvertImage(src, rgb, CV_GRAY2BGR);
// Íàõîäèì êîíòóðû øàáëîíà
cvClearMemStorage(storage);
cvFindContours(binT, storage, @contoursT, sizeof(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
if contoursT <> nil then

View File

@ -135,6 +135,7 @@ begin
contoursT := nil;
// íàõîäèì êîíòóðû èçîáðàæåíèÿ
cvClearMemStorage(storage);
contoursCont := cvFindContours(
binI,
storage,
@ -197,6 +198,7 @@ begin
CV_GRAY2BGR);
// íàõîäèì êîíòóðû øàáëîíà
cvClearMemStorage(storage);
cvFindContours(
binT,
storage,

View File

@ -77,6 +77,7 @@ begin
end;
cvCvtColor(frame, gframe, CV_BGR2GRAY);
cvThreshold(gframe, gframe, 128, 255, CV_THRESH_BINARY_INV);
cvClearMemStorage(storage);
cvFindContours(gframe, storage, @contours, SizeOf(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE,
cvPoint(0, 0));
contours := cvApproxPoly(contours, SizeOf(TCvContour), storage, CV_POLY_APPROX_DP, 5, 1);

View File

@ -113,6 +113,7 @@ begin
c := nil;
contours := AllocMem(SizeOf(TCvContour));
c := AllocMem(SizeOf(TCvContour));
cvClearMemStorage(Ctx.MyStorage);
cvFindContours(Ctx.MyThresholdImage, Ctx.MyStorage, @contours, SizeOf(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE,
cvPoint(0, 0));
if contours <> nil then

View File

@ -120,6 +120,7 @@ begin
if (image.NChannels > 1) and (cbDisplayContChecked) then
cvCvtColor(pcontor, image, CV_GRAY2BGR);
// warning! findcontours destroy the input image, so display it before the call
cvClearMemStorage(storage);
nc := cvFindContours(pcontor, storage, @contours, sizeof(TCvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE,
cvPoint(0, 0));

View File

@ -142,6 +142,7 @@ begin
// cvFindContours modifies input image, so make a copy
cvCopy(Ctx.thr_image, Ctx.temp_image1, nil);
// Íàõîäèì êîíòóðû
cvClearMemStorage(Stx.temp_st);
cvFindContours(Ctx.temp_image1, Ctx.temp_st, @contours, sizeof(TCvContour), CV_RETR_EXTERNAL,
CV_CHAIN_APPROX_NONE { CV_CHAIN_APPROX_SIMPLE } , cvPoint(0, 0));

View File

@ -69,6 +69,7 @@ begin
maxn := 0;
// function to find the white objects in the image and return the object boundaries
cvClearMemStorage(storage);
Nc := cvFindContours(img_8uc1, storage, @first_contour, SizeOf(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE,
cvPoint(0, 0));
// Try all four values and see what happens

View File

@ -169,6 +169,7 @@ begin
// generate all the contours in the threshold image as a list
contours := AllocMem(SizeOf(TCvSeq));
cvClearMemStorage(contourStorage);
n:=cvFindContours(imgThreshed, contourStorage, @contours, SizeOf(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
// find the largest contour in the list based on bounded box size

View File

@ -74,6 +74,7 @@ begin
white := CV_RGB(255, 255, 255); // Áåëûé öâåò
s_contours := AllocMem(SizeOf(TCvSeq));
// Èùåì êîíòóðû íà èçîáðàæåíèè
cvClearMemStorage(s_storage);
cvFindContours(img_in, s_storage, @s_contours, SizeOf(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
while (s_contours <> nil) do
begin
@ -117,6 +118,7 @@ begin
difference_img := remove_small_objects(difference_img, 100);
// End
contours := AllocMem(SizeOf(TCvSeq));
cvClearMemStorage(storage);
cvFindContours(difference_img, storage, @contours, SizeOf(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0, 0));
c := contours;
while (c <> nil) do

View File

@ -289,6 +289,7 @@ begin
// SetLength(
// _hierarchy,
// 0);
cvClearMemStorage(storage);
cvFindContours(
_cimage,
storage,
@ -447,6 +448,7 @@ begin
hierarchy,
0);
cvClearMemStorage(_hierarchy);
contoursCont := cvFindContours(
dst_th,
_hierarchy,

View File

@ -285,6 +285,7 @@ begin
_contours := nil;
cvClearMemStorage(_hierarchy);
contoursCont := cvFindContours(
dst_th,
_hierarchy,

View File

@ -131,6 +131,7 @@ begin
// try
// find contours and store them all as a list
cvClearMemStorage(storage);
rr := cvFindContours(gray, storage, @contours, sizeof(TCvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE,
CvPoint(0, 0));

View File

@ -215,6 +215,7 @@ begin
_contours := nil;
cvClearMemStorage(_hierarchy);
contoursCont := cvFindContours(dst_th, _hierarchy, @_contours, sizeof(TCvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE,
cvPoint(0, 0));

View File

@ -116,7 +116,7 @@
<DCC_DcuOutput>.\$(Platform)\$(Config)</DCC_DcuOutput>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;LastCompiledTime=04.08.2014 13:44:34</VerInfo_Keys>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;LastCompiledTime=06.10.2014 22:47:34</VerInfo_Keys>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>