bin auf der Suche nach einer korrekten Implementierung der Hough Transformation für Linien in Pascal,
der Code unten liefert nicht den korrekten Accumulator Inhalt zurück
Delphi-Quellcode:
THoughResult = array of array of Integer
///
/// Hough transformation for line detection
/// r = sin(theta) * a + cos(theta) * b
///
///
procedure Hough_LineDetection ( AnalysisBitmap : TBitMap; var aHoughResult : THoughResult );
var x,y, theta : integer;
r : Extended;
ImageWidth : integer;
ImageHeight : Integer;
max_d : Integer;
begin
/// size of hough array
ImageWidth := AnalysisBitmap.Width;
ImageHeight:= AnalysisBitmap.Height;
max_d := round( sqrt( ImageHeight* ImageHeight + ImageWidth * ImageWidth ) ) ;
SetLength(aHoughResult,360, max_d );
// For all rows in image do :
for y:=0 to AnalysisBitmap.Height-1 do
begin
// For all pixel in one row do :
for x:=0 to AnalysisBitmap.Width-1 do
begin
// Is there a point there or not ? If not, just skip the pixel ( threshold based methode ...)
if IsPixel(x, y, AnalysisBitmap, 128 ) then
begin
// iterate the unknown variables : ( r, theta )
// loop theta -> to be able to determine the other unknown -> r
for theta:=0 to 359 do
begin
r:=x*cos(theta*PI/360) + y*sin(theta*PI/360);
// Plot the finding (theta,r) into an array.
// Ignore negative values...
//
if r>=0 then Inc(aHoughResult[theta,round(r)]);
end;
end;
end;
end;
end;