Skip to content

Commit

Permalink
Matchtemplate: Fix small multithreading bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jul 2, 2023
1 parent 586c22d commit b7fb8b8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Source/matchtemplate/simba.matchtemplate.pas
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function Multithread(Image, Templ: TIntegerMatrix; MatchTemplate: TMatchTemplate
);
RowSize := Result.Width * SizeOf(Single);

SimbaThreadPool.RunParallel(CalculateSlices(Image.Width, Image.Height), 0, Image.Height, @Execute);
SimbaThreadPool.RunParallel(CalculateSlices(Image.Width, Image.Height), 0, Image.Height - Templ.Height, @Execute);
end;

procedure Validate(ImageWidth, ImageHeight, TemplateWidth, TemplateHeight: Integer);
Expand Down
2 changes: 1 addition & 1 deletion Source/matchtemplate/simba.matchtemplate_ccoeff.pas
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function MatchTemplateMask_CCOEFF_Cache(ACache: TMatchTemplateCacheBase; Templat
);
RowSize := Result.Width * SizeOf(Single);

SimbaThreadPool.RunParallel(CalculateSlices(Cache.Width, Cache.Height), 0, Cache.Height, @Execute);
SimbaThreadPool.RunParallel(CalculateSlices(Cache.Width, Cache.Height), 0, Cache.Height - Template.Height, @Execute);
end;

end.
Expand Down
2 changes: 1 addition & 1 deletion Source/matchtemplate/simba.matchtemplate_ccorr.pas
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function MatchTemplateMask_CCORR_Cache(ACache: TMatchTemplateCacheBase; Template
);
RowSize := Result.Width * SizeOf(Single);

SimbaThreadPool.RunParallel(CalculateSlices(Cache.Width, Cache.Height), 0, Cache.Height, @Execute);
SimbaThreadPool.RunParallel(CalculateSlices(Cache.Width, Cache.Height), 0, Cache.Height - Template.Height, @Execute);
end;

end.
Expand Down
4 changes: 2 additions & 2 deletions Source/matchtemplate/simba.matchtemplate_helpers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ implementation

uses
simba.FFTPACK4, simba.threadpool,
simba.singlematrix, simba.integermatrix;
simba.singlematrix;

function DoFFT2(const Matrix: TSingleMatrix; const outW, outH: Integer): TComplexMatrix;
var
Expand All @@ -41,7 +41,7 @@ function DoFFT2(const Matrix: TSingleMatrix; const outW, outH: Integer): TComple
H := Matrix.Height - 1;
for Y := 0 to H do
for X := 0 to W do
Spec[Y, X].Re := Matrix[Y, X];
Spec[Y, X].Re := Matrix[Y, X]; // WTF!!

Result := FFTPACK.FFT2(Spec);
end;
Expand Down
2 changes: 1 addition & 1 deletion Source/matchtemplate/simba.matchtemplate_sqdiff.pas
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function MatchTemplateMask_SQDIFF_Cache(ACache: TMatchTemplateCacheBase; Templat
);
RowSize := Result.Width * SizeOf(Single);

SimbaThreadPool.RunParallel(CalculateSlices(Cache.Width, Cache.Height), 0, Cache.Height, @Execute);
SimbaThreadPool.RunParallel(CalculateSlices(Cache.Width, Cache.Height), 0, Cache.Height - Template.Height, @Execute);
end;

function MatchTemplateMask_SQDIFF_CreateCache(Image, Template: TIntegerMatrix): TMatchTemplateCacheBase;
Expand Down
7 changes: 6 additions & 1 deletion Source/simba.threadpool.pas
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ procedure TSimbaThreadPool_Thread.Execute;
Method(Index, Lo, Hi);
except
on E: Exception do
DebugLn('Exception whilst invoking method in thread pool: ' + E.Message);
begin
DebugLn('[SimbaThreadPool]: Exception occurred while executing a method: ' + E.Message);
{$IFDEF SIMBA_HAS_DEBUGINFO}
DumpExceptionBacktrace(Output);
{$ENDIF}
end;
end;

Method := nil;
Expand Down

0 comments on commit b7fb8b8

Please sign in to comment.