Minor changes

Signed-off-by: Laentir Valetov <laex@bk.ru>
This commit is contained in:
Laentir Valetov 2014-12-09 00:19:11 +03:00
parent ef633b6695
commit 4e2cd619d0
9 changed files with 135 additions and 76 deletions

View File

@ -130,14 +130,8 @@ object Form1: TForm1
Height = 34
TabOrder = 9
inherited lbl1: TLabel
Height = 34
Margins.Bottom = 0
Caption = 'Range'
end
inherited lbl2: TLabel
Height = 34
Margins.Bottom = 0
end
inherited trckbr1: TTrackBar
Max = 40
Min = 1

View File

@ -54,7 +54,7 @@ end;
procedure TForm1.frm3trckbr1Change(Sender: TObject);
Var
R, G, B: Single;
R, G, B: Byte;
begin
((Sender as TTrackBar).Parent as TFrame2).trckbr1Change(Sender);
((ocvmgprtn1.Operations.Items[2] as TocvImageOperationCollectionItem).Operation as TocvInRangeSOperation)
@ -94,8 +94,8 @@ end;
procedure TForm1.UpdateTrack;
Var
H, S, V: Single;
R, G, B: Single;
H, S, V: Byte;
R, G, B: Byte;
H1, S1, V1: Integer;
begin
pnl1.Caption := '(R:' + SelectedPixel.R.ToString() + ',G:' + SelectedPixel.G.ToString() + ',B:' +

View File

@ -1,4 +1,4 @@
program cObjecColorTracking;
program cObjectColorTracking;
uses
Vcl.Forms,

View File

@ -3,7 +3,7 @@
<ProjectGuid>{E56078FF-356A-459E-9A21-AD24F8DD0A4A}</ProjectGuid>
<ProjectVersion>16.1</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<MainSource>cObjecColorTracking.dpr</MainSource>
<MainSource>cObjectColorTracking.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
@ -43,7 +43,7 @@
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Locale>1049</VerInfo_Locale>
<SanitizedProjectName>cObjecColorTracking</SanitizedProjectName>
<SanitizedProjectName>cObjectColorTracking</SanitizedProjectName>
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace)</DCC_Namespace>
<DCC_DcuOutput>.\$(Platform)\$(Config)</DCC_DcuOutput>
<DCC_ExeOutput>..\..\..\bin\$(Platform)</DCC_ExeOutput>
@ -57,7 +57,6 @@
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
<DCC_UsePackage>cxSchedulerTreeBrowserRS20;JvGlobus;JvMM;cxGridRS20;dxFireDACServerModeRS20;JvManagedThreads;NxGridRun_dxe7;dxPScxExtCommonRS20;dxPSdxLCLnkRS20;dxSkinOffice2007SilverRS20;cxPageControlRS20;dxPSdxSpreadSheetLnkRS20;FireDACPgDriver;JvCrypt;DBXInterBaseDriver;DataSnapServer;DataSnapCommon;JvNet;dxSkinsdxBarPainterRS20;dxSkinSharpRS20;JvDotNetCtrls;DbxCommonDriver;dxLayoutControlRS20;vclimg;dxSkinSilverRS20;NxDBGridRun_dxe7;dbxcds;dxSkinsdxNavBarPainterRS20;DatasnapConnectorsFreePascal;JvXPCtrls;NxCommonDsgn_dxe7;dxPSCoreRS20;dxSkinOffice2013LightGrayRS20;vcldb;NxSheetRun_dxe7;dxPSTeeChartRS20;dxSkinOffice2013WhiteRS20;dxSkinMcSkinRS20;CustomIPTransport;NxCollectionDsgn_dxe7;dsnap;IndyIPServer;dxSkinCoffeeRS20;dxSkinGlassOceansRS20;IndyCore;dxSkinOffice2010SilverRS20;dxComnRS20;CloudService;dxFlowChartRS20;dxSkinOffice2013DarkGrayRS20;FmxTeeUI;FireDACIBDriver;dxDBXServerModeRS20;cxTreeListdxBarPopupMenuRS20;dxSkinOffice2007PinkRS20;dxSkinSpringTimeRS20;dxPsPrVwAdvRS20;JvDB;JvRuntimeDesign;dxPScxGridLnkRS20;dxSkiniMaginaryRS20;dxSkinDevExpressDarkStyleRS20;cxSchedulerGridRS20;dxtrmdRS20;dsnapxml;JclDeveloperTools;FireDACDb2Driver;NxDBGridDsgn_dxe7;dxSpreadSheetRS20;dxSkinMoneyTwinsRS20;dxSkinOffice2007GreenRS20;dxPScxTLLnkRS20;cxPivotGridOLAPRS20;dxPSdxFCLnkRS20;bindcompfmx;FireDACODBCDriver;RESTBackendComponents;dbrtl;FireDACCommon;bindcomp;inetdb;JvPluginSystem;DBXOdbcDriver;JvCmp;vclFireDAC;JvTimeFramework;xmlrtl;cxSpreadSheetRS20;ibxpress;dxSkinOffice2007BlackRS20;dxPScxSSLnkRS20;FireDACCommonDriver;bindengine;vclactnband;soaprtl;FMXTee;dxGDIPlusRS20;bindcompvcl;Jcl;vclie;cxVerticalGridRS20;cxSchedulerRS20;dxSkinBlackRS20;FireDACMSSQLDriver;DBXInformixDriver;dxSkinSummer2008RS20;Intraweb;cxBarEditItemRS20;DataSnapServerMidas;dsnapcon;DBXFirebirdDriver;inet;dxBarRS20;cxDataRS20;dxSkinDarkSideRS20;JvPascalInterpreter;FireDACMySQLDriver;soapmidas;vclx;dxPScxVGridLnkRS20;dxSkinLondonLiquidSkyRS20;dxCoreRS20;DBXSybaseASADriver;RESTComponents;dxPSPrVwRibbonRS20;dbexpress;dxPSLnksRS20;IndyIPClient;dxSpellCheckerRS20;dxBarExtItemsRS20;dxdbtrRS20;FireDACSqliteDriver;FireDACDSDriver;cxSchedulerRibbonStyleEventEditorRS20;DBXSqliteDriver;fmx;dxSkinVS2010RS20;JvDlgs;IndySystem;frxe21;TeeDB;tethering;dxPScxPCProdRS20;dxSkinXmas2008BlueRS20;vclib;dxTabbedMDIRS20;DataSnapClient;frx21;dxmdsRS20;DataSnapProviderClient;DBXSybaseASEDriver;dxdborRS20;dxPSdxDBTVLnkRS20;MetropolisUILiveTile;dxPScxSchedulerLnkRS20;dxSkinCaramelRS20;dxSkinLiquidSkyRS20;vcldsnap;dxGaugeControlRS20;dxSkinDevExpressStyleRS20;fmxFireDAC;cxPivotGridChartRS20;DBXDb2Driver;DBXOracleDriver;dxSkinOffice2010BlueRS20;JvCore;dcldxSkinsCoreRS20;vclribbon;cxExportRS20;dxServerModeRS20;dxSkinscxSchedulerPainterRS20;dxSkinMetropolisDarkRS20;fmxase;vcl;DBXMSSQLDriver;IndyIPCommon;CodeSiteExpressPkg;dxSkinBlueRS20;dxSkinsdxDLPainterRS20;DataSnapFireDAC;FireDACDBXDriver;dxBarExtDBItemsRS20;JvAppFrm;soapserver;dxPSDBTeeChartRS20;dxSkinOffice2010BlackRS20;inetdbxpress;dxADOServerModeRS20;dxSkinBlueprintRS20;dxSkinFoggyRS20;dxSkinSharpPlusRS20;FireDACInfxDriver;cxPivotGridRS20;JvDocking;adortl;JvWizards;dxRibbonRS20;FireDACASADriver;dxSkinHighContrastRS20;JvHMI;dxSkinTheAsphaltWorldRS20;JvBands;NxInspectorRun_dxe7;dxBarDBNavRS20;dxSkinscxPCPainterRS20;emsclientfiredac;rtl;DbxClientDriver;frxTee21;dxNavBarRS20;dxSkinMetropolisRS20;dxDockingRS20;Tee;JclContainers;dxSkinOffice2007BlueRS20;dxSkinsdxRibbonPainterRS20;frxDB21;dxSkinValentineRS20;JvSystem;DataSnapNativeClient;svnui;JvControls;IndyProtocols;DBXMySQLDriver;dxPScxCommonRS20;dxSkinSevenClassicRS20;dxSkinPumpkinRS20;bindcompdbx;TeeUI;JvJans;JvPrintPreview;JvPageComps;JvStdCtrls;JvCustom;NxCommonRun_dxe7;dxSkinDarkRoomRS20;FireDACADSDriver;vcltouch;NxInspectorDsgn_dxe7;dxSkinStardustRS20;cxEditorsRS20;emsclient;dxorgcRS20;dxPSdxDBOCLnkRS20;VCLRESTComponents;FireDAC;VclSmp;NxGridDsgn_dxe7;dxSkinsCoreRS20;DataSnapConnectors;dxSkinSevenRS20;cxLibraryRS20;fmxobj;NxCollectionRun_dxe7;JclVcl;OpenCV210;dxMapControlRS20;svn;dxWizardControlRS20;dxSkinLilianRS20;FireDACOracleDriver;fmxdae;dxPScxPivotGridLnkRS20;dxSkinWhiteprintRS20;dxPSdxOCLnkRS20;dxThemeRS20;FireDACMSAccDriver;DataSnapIndy10ServerTransport;cxTreeListRS20;dxTileControlRS20;$(DCC_UsePackage)</DCC_UsePackage>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
</PropertyGroup>
@ -114,7 +113,7 @@
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">cObjecColorTracking.dpr</Source>
<Source Name="MainSource">cObjectColorTracking.dpr</Source>
</Source>
<Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k210.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
@ -122,9 +121,15 @@
</Excluded_Packages>
</Delphi.Personality>
<Deployment>
<DeployFile LocalName="Win32\Debug\cObjecColorTracking.exe" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="..\..\..\bin\Win32\cObjectColorTracking.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>cObjecColorTracking.exe</RemoteName>
<RemoteName>cObjectColorTracking.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="Win32\Debug\cObjectColorTracking.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>cObjectColorTracking.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>

View File

@ -74,12 +74,23 @@ type
Radius: Integer;
end;
TocvColorEncode = (ceRGB, ceGRAY);
TocvPixel = record
r, g, b, a: byte;
case c: TocvColorEncode of
ceRGB:
(R, G, B: byte);
ceGRAY:
(GV: byte);
end;
{$IFDEF DELPHIXE_UP}
const
cmRGB: TA4CVChar = 'RGB'#0;
cmBGR: TA4CVChar = 'BGR'#0;
cmGRAY: TA4CVChar = 'GRAY';
Type
{$IFDEF DELPHIXE_UP}
TocvRects = TArray<TocvRect>;
TocvCircles = TArray<TocvCircle>;
TocvLines = TArray<TocvLine>;
@ -123,7 +134,7 @@ type
const LineType: TocvLineType = LT_8; const Shift: Integer = 0); overload;
procedure Rectangle(const ARect: TocvRect; const Color: TColor = clRed; const Thickness: Integer = 1;
const LineType: TocvLineType = LT_8; const Shift: Integer = 0); overload;
procedure Circle(const x, y, r: Integer; const Color: TColor = clRed; const Thickness: Integer = 1;
procedure Circle(const x, y, R: Integer; const Color: TColor = clRed; const Thickness: Integer = 1;
const LineType: TocvLineType = LT_8; const Shift: Integer = 0);
procedure Ellipse(const CenterX, CenterY: Integer; const Axes: TocvRect; const Angle: double;
const start_angle: double; const nd_angle: double; const Color: TColor = clRed; const Thickness: Integer = 1;
@ -364,9 +375,11 @@ function ocvRect(Left, Top, Right, Bottom: Integer): TocvRect;
function ocvRectCenter(cX, cY, Width, Height: Integer): TocvRect;
function cvRect(const oRect: TocvRect): TcvRect;
procedure GetRGBValue(const AColor: TColor; var r, g, b: byte);
procedure GetRGBValue(const AColor: TColor; var R, G, B: byte);
function ColorToCvRGB(const Color: TColor): TCvScalar;
function ocvPixel(const R, G, B: byte): TocvPixel;
const
cLineType: array [TocvLineType] of Integer = (CV_FILLED, 8, CV_AA);
@ -377,6 +390,14 @@ uses
ocv.imgproc.types_c,
ocv.highgui_c, ocv.cvutils;
function ocvPixel(const R, G, B: byte): TocvPixel;
begin
Result.c := ceRGB;
Result.R := R;
Result.G := G;
Result.B := B;
end;
function cvRect(const oRect: TocvRect): TcvRect;
begin
Result := ocv.core.types_c.cvRect(oRect.Left, oRect.Top,
@ -467,13 +488,13 @@ end;
procedure TocvDataSource.NotifyReceiver(const IplImage: IocvImage);
Var
r: Pointer; // IocvDataReceiver;
R: Pointer; // IocvDataReceiver;
LockList: TList; // <IocvDataReceiver>;
begin
LockList := FOpenCVVideoReceivers.LockList;
try
for r in LockList do
IocvDataReceiver(r).TakeImage(IplImage);
for R in LockList do
IocvDataReceiver(R).TakeImage(IplImage);
finally
FOpenCVVideoReceivers.UnlockList;
end;
@ -647,14 +668,51 @@ end;
function TocvImage.GetPixel(const x, y: Integer): TocvPixel;
begin
Result.b := byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 0)^);
Result.g := byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 1)^);
Result.r := byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 2)^);
FillChar(Result, SizeOf(Result), 0);
if FImage.colorModel = cmRGB then
begin
Result.c := ceRGB;
if FImage.channelSeq = cmRGB then
begin
Result.R := byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 0)^);
Result.G := byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 1)^);
Result.B := byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 2)^);
end
else
begin
Result.B := byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 0)^);
Result.G := byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 1)^);
Result.R := byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 2)^);
end;
end
else if FImage.colorModel = cmGRAY then
begin
Result.c := ceGRAY;
Result.GV := byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels))^);
end;
end;
procedure TocvImage.SetPixel(const x, y: Integer; const P: TocvPixel);
begin
case P.c of
ceRGB:
begin
if FImage.channelSeq = cmRGB then
begin
byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 0)^) := P.R;
byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 1)^) := P.G;
byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 2)^) := P.B;
end
else
begin
byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 0)^) := P.B;
byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 1)^) := P.G;
byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels) + 2)^) := P.R;
end;
end;
ceGRAY:
byte(CV_IMAGE_ELEM(FImage, SizeOf(byte), y, (x * FImage^.nChannels))^) := P.GV;
end;
end;
function TocvImage.GetHeight: Integer;
@ -704,11 +762,11 @@ end;
function TocvImage.Resize(const nW, nH: Integer; const interpolation: Integer = CV_INTER_LINEAR): IocvImage;
Var
r: pIplImage;
R: pIplImage;
begin
r := cvCreateImage(cvSize(nW, nH), FImage^.depth, FImage^.nChannels);
cvResize(FImage, r, interpolation);
Result := TocvImage.Create(r);
R := cvCreateImage(cvSize(nW, nH), FImage^.depth, FImage^.nChannels);
cvResize(FImage, R, interpolation);
Result := TocvImage.Create(R);
end;
function TocvImage.Same: IocvImage;
@ -733,22 +791,22 @@ begin
inherited Remove(Pointer(Item));
end;
procedure GetRGBValue(const AColor: TColor; var r, g, b: byte);
procedure GetRGBValue(const AColor: TColor; var R, G, B: byte);
Var
RGBColor: TColor;
begin
RGBColor := ColorToRGB(AColor);
r := GetRValue(RGBColor);
g := GetGValue(RGBColor);
b := GetBValue(RGBColor);
R := GetRValue(RGBColor);
G := GetGValue(RGBColor);
B := GetBValue(RGBColor);
end;
function ColorToCvRGB(const Color: TColor): TCvScalar;
var
r, g, b: byte;
R, G, B: byte;
begin
GetRGBValue(Color, r, g, b);
Result := CV_RGB(r, g, b);
GetRGBValue(Color, R, G, B);
Result := CV_RGB(R, G, B);
end;
{ TocvCanvas }
@ -837,7 +895,7 @@ end;
constructor TocvFont.Create;
begin
inherited;
FillChar(FCvFont, sizeof(FCvFont), 0);
FillChar(FCvFont, SizeOf(FCvFont), 0);
FCvFont.HScale := 0.5;
FCvFont.VScale := 0.5;
FCvFont.Thickness := 1;
@ -927,7 +985,7 @@ end;
function TocvRectHelper.cvRect: TcvRect;
Var
r: TcvRect;
R: TcvRect;
begin
Result.x := Left;
Result.y := Top;

View File

@ -85,8 +85,8 @@ function BitmapToIplImage(const bitmap:
{$IFDEF DELPHIXE2_UP}Vcl.Graphics.TBitmap{$ELSE}Graphics.TBitmap{$ENDIF}): PIplImage;
function CropIplImage(const src: PIplImage; const roi: TCvRect): PIplImage;
procedure ocvRGBToHSV(const R, G, B: single; out H, S, V: single);
procedure ocvHSVToRGB(H, S, V: single; out R, G, B: single);
procedure ocvRGBToHSV(const R, G, B: byte; out _H, _S, _V: byte);
procedure ocvHSVToRGB(const _H, _S, _V: byte; out _R, _G, _B: byte);
implementation
@ -442,7 +442,7 @@ begin
end;
end;
procedure ocvHSVToRGB(H, S, V: single; out R, G, B: single);
procedure ocvHSVToRGB(const _H, _S, _V: byte; out _R, _G, _B: byte);
{
in
H = Hue. Range is from 0..180. or H < 0 for gray
@ -463,64 +463,65 @@ var
SectionIndex: Integer;
F: single;
p, q, t: single;
H, S: single;
begin
H := H / 180;
S := S / 255;
H := _H / 180;
S := _S / 255;
if H < 0 then
begin
R := V;
G := R;
B := R;
_R := _V;
_G := _R;
_B := _R;
end
else
begin
Section := H / SectionSize;
SectionIndex := Floor(Section);
F := Section - SectionIndex;
p := V * (1 - S);
q := V * (1 - S * F);
t := V * (1 - S * (1 - F));
p := _V * (1 - S);
q := _V * (1 - S * F);
t := _V * (1 - S * (1 - F));
case SectionIndex of
0:
begin
R := V;
G := t;
B := p;
_R := _V;
_G := Trunc(t);
_B := Trunc(p);
end;
1:
begin
R := q;
G := V;
B := p;
_R := Trunc(q);
_G := _V;
_B := Trunc(p);
end;
2:
begin
R := p;
G := V;
B := t;
_R := Trunc(p);
_G := _V;
_B := Trunc(t);
end;
3:
begin
R := p;
G := q;
B := V;
_R := Trunc(p);
_G := Trunc(q);
_B := _V;
end;
4:
begin
R := t;
G := p;
B := V;
_R := Trunc(t);
_G := Trunc(p);
_B := _V;
end;
else
R := V;
G := p;
B := q;
_R := _V;
_G := Trunc(p);
_B := Trunc(q);
end;
end;
end;
procedure ocvRGBToHSV(const R, G, B: single; out H, S, V: single);
procedure ocvRGBToHSV(const R, G, B: byte; out _H, _S, _V: byte);
{
in
R = 0..255
@ -536,6 +537,7 @@ var
rgb: array [0 .. 2] of single;
MinIndex, MaxIndex: Integer;
Range: single;
H, S, V: single;
begin
rgb[0] := R;
rgb[1] := G;
@ -560,9 +562,9 @@ begin
// Check for a gray level
if Range = 0 then
begin
H := -1; // Can't determine on greys, so set to -1
S := 0; // Gray is at the center;
V := R; // could choose R, G, or B because they are all the same value.
_H := 0; // Can't determine on greys, so set to -1
_S := 0; // Gray is at the center;
_V := R; // could choose R, G, or B because they are all the same value.
end
else
begin
@ -580,9 +582,9 @@ begin
if H < 0 then
H := 1 + H;
H := H * 180;
S := S * 255;
V := V;
_H := Trunc(H * 180);
_S := Trunc(S * 255);
_V := Trunc(V);
end;
end;