![]() |
Memeber Acces Operators in Delph
Tach!
ich habe ein klitzekleines Prozedürchen in Delphi umzusetzen. Da kommt dieses M.A.O. -> vor. Wie könnte das hier in Delphi aussehhen
Delphi-Quellcode:
Also, die Deklaration ist mir klar, wie das geht, vielmehr interessiert mich die Umsetzung der 3 Zeilen zwischen den Klammern :gruebel: void GetRGB( RGBTRIPLE* prgb, //Pointer to the pixel BYTE *R, BYTE *G, BYTE *B) //Output: R, G and B { *R=prgb->rgbtRed; *G=prgb->rgbtGreen; *B=prgb->rgbtBlue; } Danke! |
Re: Memeber Acces Operators in Delph
Vielleicht so:
*R=^prgb.rgbtRed; ?? |
Re: Memeber Acces Operators in Delph
Delphi-Quellcode:
Oder vielleicht So? :angle2:implementation procedure GetRGB( prgb: pRGBTRIPLE; //Pointer to the pixel R,G,B: pBYTE); //Output: R, G and B begin R^:=prgb.rgbtRed; G^:=prgb.rgbtGreen; B^:=prgb.rgbtBlue; end; |
Re: Memeber Acces Operators in Delph
Code:
void GetRGB(
RGBTRIPLE* prgb, //Pointer to the pixel BYTE *R, BYTE *G, BYTE *B) //Output: R, G and B { *R=prgb->rgbtRed; *G=prgb->rgbtGreen; *B=prgb->rgbtBlue; }
Delphi-Quellcode:
Procedure GetRGB(Const prgb : PRGBTRIPLE;Var R,G,B : Byte);
Begin R:=prgb^.rgbtRed; G:=prgb^.rgbtGreen; B:=prgb^.rgbtBlue; end; |
Re: Memeber Acces Operators in Delph
Zitat:
Danke. Könntest Du mir vielleicht den Unterschied zwischen Deinem und meinem Ansatz erläutern? :wall: |
Re: Memeber Acces Operators in Delph
@ Virchov: R, G und B sind Zeiger auf Byte-Werte. Du weist diesen Zeigern aber die Werte selbst zu, nicht die Adressen!
|
Re: Memeber Acces Operators in Delph
während ich meinen Beitrag geschrieben habe, bist Du mit Deinem zuvorgekommen... grundsätzlich ist es das selbe... der Unterschied ist die Art der Wertrückgabe von R,G und B... in C verwendet man häufig Pointer (BYTE*) zur Wertrückgabe, während im Delphi dazu das VAR-Schlüsselwort verwendet werden kann... Du hast nun diese Art der Wertrückgabe übernommen, ich habe sie auf die Delphi-übliche Variante realisiert.... im Assembler-Code würden beide Ansätze nahezu identisch aussehen....
|
Re: Memeber Acces Operators in Delph
Zitat:
Hmmm. Verstehe ich Dich richtig: ^R ist ein Pointer auf Pointer auf pByte; R ist ein Pointer auf pByte; R^ ist die pByte- Variable, auf die der Pointer zeigt Richtig? :oops: |
Re: Memeber Acces Operators in Delph
Und das? Ich bin völlig verwirrt....
Delphi-Quellcode:
Ist das nicht dasselbe wie
R^:=prgb^.rgbtRed; ;
G^:=prgb^.rgbtGreen; B^:=prgb^.rgbtBlue;
Delphi-Quellcode:
das hier? :duck:
R:=prgb^.rgbtRed; ;
G:=prgb^.rgbtGreen; B:=prgb^.rgbtBlue; |
Re: Memeber Acces Operators in Delph
@ Virchov: Also: R, G und B sind vom Typ PByte, das sollte ein Pointer auf einen Byte-Wert sein.
prgb ist ein Pointer pRGBTRIPLE. Dieses enthält wohl drei Byte-Werte.
Delphi-Quellcode:
Zunächst: prgb^.rgbtRed ist das gleiche wie prgb.rgbtRed.
R^:=prgb^.rgbtRed; ;
G^:=prgb^.rgbtGreen; B^:=prgb^.rgbtBlue; Du weißt also der Speicherstelle, auf die R zeigt, den Wert von prgb.rgbtRed zu.
Delphi-Quellcode:
Hier weißt du der Variable R den Wert im Record zu.
R:=prgb^.rgbtRed; ;
G:=prgb^.rgbtGreen; B:=prgb^.rgbtBlue; Ich hab übrigens da oben Mist geschrieben, vergesst das. Die Lösung von Basilikum entspricht allerdings der deinen, da er die Parameter als Referenz abruft. Dadurch kann er mit ihnen hantieren, als wären es Wertvariabeln, allerdings sind es Zeigervariablen. |
Re: Memeber Acces Operators in Delph
Ich hätte es wahrscheinlich so formuliert
Delphi-Quellcode:
procedure GetRGB(const prgb: TRGBTRIPLE; var R,G,B: Byte);
begin R :=prgb.rgbtRed; G :=prgb.rgbtGreen; B :=prgb.rgbtBlue; end; |
Re: Memeber Acces Operators in Delph
Zitat:
*p dereferenziert p und zeigt somit auf den Inhalt von p (p^). p->v dereferenziert den Struktur-Zeiger p und gibt v zurück (p.val); Die ganzen De-/Referenzierungen kann man in der Delphi Language einfacher haben:
Delphi-Quellcode:
procedure GetRGB(const RGB: TRGBTriple; out R, G, B: Byte);
begin R := RGB.rgbtRed; G := RGB.rgbtGreen; B := RGB.rgbtBlue; end; |
Re: Memeber Acces Operators in Delph
@Nico: deswegen (deine Erklärung) ziehe ich eine der Letzten beiden Varianten vor
|
Re: Memeber Acces Operators in Delph
:roteyes:
Danke, allerseits! :roteyes: |
Re: Memeber Acces Operators in Delph
Scheiße!
Der Compiler sagt "nicht genügend wirkliche Parameter"... Ich habe die Variante von Nico genommen.. :cry: |
Re: Memeber Acces Operators in Delph
Zitat:
|
Re: Memeber Acces Operators in Delph
Moin, NICO!
Der C -Code sieht ungefähr so aus:
Delphi-Quellcode:
void GetROI_CAL_RGB_VIS(
RGBTRIPLE* prgb, //Pointer to first pixel int cxImage, int cyImage, //Width, Height of total image bool ShowBoundingBox, //if !0, Bounding Box is drawn bool ShowROIHistogram, //if !0, ROI Histogram is drawn int* roiPosArray, //Array containg ROI positions bool* roiMask, //Mask,pixel[i] is in ROI if roiMask[i] int* minLeft, int* maxLeft, //Vertical Bounding Box Scanlines int* minTop, int* maxTop, //Horizontal Bounding Box Scanlines int *numROIPixels, //number of pixels contained in ROI bool Check4Rect, //1 = check for ellipse and rectangle, 0 just ellipse float fROICutOffLevel //ROI minimal Histogram presence ) { //declares BYTE V; //Brightness (V=Max(R,G,B)) BYTE R,G,B; //Red, Green, Blue int Histogram[LENBYTE]={0}; //Brightness Histogram for this frame const int numPixels = cxImage*cyImage; //Total number of pixels BYTE roiTreshold; //Treshold for non-ROI exclusion static BYTE roiHistogramMax=0; //Maximum of times a certain pixel was in ROI register idx; //Loop counter for pixels static BYTE roiHistogram[STATICMASKSIZE] = {0}; //Times a pixel was included to ROI because of low brightness RGBTRIPLE* prgb0 = prgb; //Pointer to pixel (0,0) const int centerCrossRadius = 5; //Size of the cross mark representing the center. int* YPosArray; //Array containing vertical roi-edges int* PosArrayRect; //temp. array containing roi-edges static bool OTSUMask[STATICMASKSIZE]; //mask containing !0 for each pix>OTSUthreshold static bool EllipseMask[STATICMASKSIZE]; //mask derived from the ellipse approximation static bool RectMask[STATICMASKSIZE]; //mask derived from the rectangle approximation static int ROIBase=0; //Contains counter for number of frames the roi is based on //allocate memory for temporary buffers YPosArray = (int*) calloc(cxImage*2,sizeof(int)); PosArrayRect = (int*) calloc(cyImage*2,sizeof(int)); //Flip Bounding Box fictive values, which are adjusted later on *minTop=cyImage-1, *maxTop=0; *minLeft=cxImage-1; *maxLeft=0; //Build Brightness Histogram of this frame only GetBrightnessHistogram(prgb, numPixels, 0, Histogram); prgb=prgb0; //Get Treshold for roi and store it in variable roiTreshold roiTreshold = (BYTE)(ROISENSE*getTresholdOTSU(Histogram, numPixels)); //Find roi using treshold and create a roi/time histogram for (prgb=prgb0, idx=0; idx < numPixels; idx++, prgb++){ //processing in RGB space, V-channel = max(R,G,B) [color=red] GetRGB(prgb,R,G,B);[/color] V=GetTripleMax(R,G,B); if ((V > roiTreshold) && (V<=MAXBYTE)){ //Store the fact that this pixel was >OSTU threshold // DO NOT use V >= roiThreshold // (why? test an image with an image containing only values of 0 and 255) OTSUMask[idx]=1; if (roiHistogram[idx] < MAXBYTE){ //Raise number of times this pixel was included in ROI, with a max of MAXBYTE roiHistogram[idx]++; if (roiHistogram[idx] > roiHistogramMax) roiHistogramMax = roiHistogram[idx]; } // roiHistogram<MAXBYTE } else { OTSUMask[idx]=0; // added by BF in order to be able to remove errand pixels again from roi: if (roiHistogram[idx] > 0) roiHistogram[idx]--; } // else //Set this pixel to 1 in the mask if they are more then % of the times //detected as higher than the treshold //else added by BF, Jul 11, 2003 if ((roiHistogram[idx] / (float)roiHistogramMax) > fROICutOffLevel) roiMask[idx] = 1; else roiMask[idx] = 0; } // for prgb,idx prgb = prgb0; ROIBase++; ....Jetzt ist folgendes Problem aufgetreten. Das Parameter "RGB" habe ich in PRGB umbenannt, da RGB so eine Art reserviertes Wort in Delphi ist. Nun sagt der Compiler das hier: Incompatible Typen: Tagrgbtriple und "prgbtriple" ps Den Code habe ich schon übersetzt in D., nur poste ich den hier in C (ausser dieser rotmarkierten Zeile) übersichtlichkeitshalber Danke! |
Re: Memeber Acces Operators in Delph
aber so gin es!! Wäre es richtig so?
Delphi-Quellcode:
ps Ich habe Dereferenzierung von PRGB vorgenommen , also statt PRGB, PRGB^ rinjeschrieben.
GetRGB (PRGB^,R,G,B);
pps Nochmal: GetRgb ist früher folgendermaßen deklariert worden:
Delphi-Quellcode:
Also, liege ich da richtig oder das mit der Deref. ist verkehrt? :gruebel:procedure GetRGB( PRGB: TRGBTRIPLE; //Pointer to the pixel var R,G,B: BYTE); //Output: R, G and B begin R:=prgb.rgbtRed; ; G:=prgb.rgbtGreen; B:=prgb.rgbtBlue; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:56 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz