0% found this document useful (0 votes)
111 views5 pages

Video Lab Unit 1

The document describes a program that performs image processing and color analysis. It defines classes, variables, and procedures for capturing an image, extracting a region of the image, and analyzing the average red, green, and blue pixel values in that region to identify the color. Key steps include: 1. Capturing an image with a camera and displaying it. 2. Extracting a rectangular region of the captured image and copying it to a new image. 3. Analyzing the pixel values in the region by calculating the average red, green, and blue values across columns. 4. Comparing the average values to thresholds to identify the color as iron cabinet, white paper, or unknown.

Uploaded by

Dewa Djantra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views5 pages

Video Lab Unit 1

The document describes a program that performs image processing and color analysis. It defines classes, variables, and procedures for capturing an image, extracting a region of the image, and analyzing the average red, green, and blue pixel values in that region to identify the color. Key steps include: 1. Capturing an image with a camera and displaying it. 2. Extracting a rectangular region of the captured image and copying it to a new image. 3. Analyzing the pixel values in the region by calculating the average red, green, and blue values across columns. 4. Comparing the average values to thresholds to identify the color as iron cabinet, white paper, or unknown.

Uploaded by

Dewa Djantra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, VLCommonDisplay, VLImageDisplay,

VLDSCapture, ExtCtrls, VLCommonFilter, VLGenericFilter, StdCtrls; type TForm1 = class(TForm) VLGenericFilter1: TVLGenericFilter; Timer1: TTimer; Timer2: TTimer; Button1: TButton; VLDSCapture1: TVLDSCapture; Button2: TButton; Memo1: TMemo; Memo2: TMemo; Memo3: TMemo; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label8: TLabel; Timer3: TTimer; GroupBox1: TGroupBox; Image1: TImage; GroupBox2: TGroupBox; Image2: TImage; Label9: TLabel; Label10: TLabel; Label11: TLabel; GroupBox3: TGroupBox; Label6: TLabel; Label7: TLabel; Label12: TLabel; Label13: TLabel; Label14: TLabel; procedure VLGenericFilter1ProcessData(Sender: TObject; InBuffer: IVLImageBuffer; var OutBuffer: IVLImageBuffer; var SendOutputData: Boolean); procedure Timer1Timer(Sender: TObject); procedure Timer2Timer(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Timer3Timer(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; xL, yT, xR, yB, xTemp, yTemp: integer; RB,GB,bb : array[0..7000] of extended; Jum_kolomR,Jum_kolomG,Jum_kolomB : extended;

R,g,B : array[0..1000,0..1000] of extended; implementation {$R *.dfm} procedure TForm1.VLGenericFilter1ProcessData(Sender: TObject; InBuffer: IVLImageBuffer; var OutBuffer: IVLImageBuffer; var SendOutputData: Boolean); begin InBuffer.Data().ToBitmap( Image1.Picture.Bitmap ); // Update Screen. Image1.Refresh(); end; procedure Olah; var x, y, x1, y1, w, h, w1, h1: integer; PC, PH: PByteArray; Ki, Ri, Gi, Bi, Ko, Ro, Go, Bo: array of array of byte; begin w := form1.Image1.Picture.Width; h := form1.Image1.Picture.Height; xL := 110; yT:= 75 ; xR := 150 ; yB := 125 ; w1 := (xR-xL); h1 := (yB-yT); form1.Image2.Picture.Bitmap.Width := w1; form1.Image2.Picture.Bitmap.Height := h1; begin SetLength(Ri, w, h); SetLength(Gi, w, h); SetLength(Bi, w, h); SetLength(Ro, w1, h1); SetLength(Go, w1, h1); SetLength(Bo, w1, h1); for y := 0 to h-1 do begin PC := form1.Image1.Picture.Bitmap.ScanLine[y]; for x := 0 to w-1 do begin Bi[x, y] := PC[3*x]; Gi[x, y] := PC[3*x+1]; Ri[x, y] := PC[3*x+2]; end; end; for x1 := 0 to w1-1 do for y1 := 0 to h1-1 do begin x := x1+xL; y := y1+yT; Ro[x1, y1] := Ri[x, y]; Go[x1, y1] := Gi[x, y]; Bo[x1, y1] := Bi[x, y]; end; for y1 := 0 to h1-1 do begin PH := form1.Image2.Picture.Bitmap.ScanLine[y1];

for x1 := 0 to w1-1 do begin PH[3*x1] := Bo[x1, y1]; PH[3*x1+1] := Go[x1, y1]; PH[3*x1+2] := Ro[x1, y1]; end; end; Ri := nil; Gi := nil; Bi := nil; Ro := nil; Go := nil; Bo := nil; end; end; procedure TForm1.Timer1Timer(Sender: TObject); begin timer2.enabled := true; end; procedure TForm1.Timer2Timer(Sender: TObject); begin timer2.enabled := false; Image2.Picture := Image1.Picture; //Olah; // label1.Caption := inttostr(image2.picture.bitmap.Width); // label2.caption := inttostr(image2.picture.bitmap.height); timer2.enabled := true;

end; procedure TForm1.Button1Click(Sender: TObject); begin vldscapture1.enabled := true; vlgenericFilter1.enabled :=true; timer1.enabled := true; end; procedure TForm1.Button2Click(Sender: TObject); begin timer3.Enabled := true; end; procedure TForm1.Timer3Timer(Sender: TObject); var kolom,baris,kaxis : integer; ratar,ratag,ratab : real; begin

timer3.Enabled := false; for kolom := 0 to image2.picture.bitmap.Width-1 do begin for baris := 0 to image2.picture.bitmap.height-1 do begin R[kolom,baris] := getRvalue(image2.Picture.bitmap.canvas.pixels[kolom,baris]); G[kolom,baris] := getGvalue(image2.Picture.bitmap.canvas.pixels[kolom,baris]); B[kolom,baris] := getBvalue(image2.Picture.bitmap.canvas.pixels[kolom,baris]); end; end; for kolom begin RB[kolom] GB[kolom] BB[kolom] end; for kolom

:= 0 to image2.picture.bitmap.Width-1 do := 0; := 0; := 0; := 0 to image2.picture.bitmap.Width-1 do

for baris := 0 to image2.picture.bitmap.height-1 do begin RB[kolom] := rb[kolom] + R[kolom,baris]; GB[kolom] := GB[kolom] + G[kolom,baris]; BB[kolom] := bb[kolom] + B[kolom,baris]; end; Jum_kolomR := 0; Jum_kolomG := 0; Jum_kolomB := 0; for kolom := 0 to image2.picture.bitmap.Width-1 do begin Jum_kolomR := Jum_kolomR + RB[kolom]; Jum_kolomG := Jum_kolomG + GB[kolom]; Jum_kolomB := Jum_kolomB + BB[kolom]; memo1.lines.Add(floattostr(Rb[kolom])); memo2.lines.Add(floattostr(Gb[kolom])); memo3.lines.Add(floattostr(bb[kolom])); end; RataR := Jum_kolomR/(image2.picture.bitmap.Width*image2.picture.bitmap.height); RataG := Jum_kolomG/(image2.picture.bitmap.Width*image2.picture.bitmap.height); RataB := Jum_kolomB/(image2.picture.bitmap.Width*image2.picture.bitmap.height); label3.caption := floattostr(ratar); label4.caption := floattostr(ratag); label5.caption := floattostr(ratab); label12.caption := floattostr(Jum_kolomR); label13.caption := floattostr(Jum_kolomG); label14.caption := floattostr(Jum_kolomB); label7.caption := inttostr(image2.picture.bitmap.Width*image2.picture.bitmap.hei ght); begin if ((rataR>=137) and (rataR<=139)) and (( RataG>=150)and(rataG<=152)) and (( Ra tab>=140)and(ratab<=143)) then

label6.Caption := ' Lemari Besi' ; if ((rataR>=152) and (rataR<=156)) and (( RataG>=171)and(rataG<=177)) and (( Ra tab>=169)and(ratab<=176)) then label6.Caption := ' Kertas Putih' else label6.Caption := ' unknow' ;

end; timer3.Enabled := true; end; end.

You might also like