mirror of
https://github.com/Laex/Delphi-OpenCV.git
synced 2024-11-18 01:05:53 +01:00
110 lines
2.9 KiB
ObjectPascal
110 lines
2.9 KiB
ObjectPascal
|
{$APPTYPE CONSOLE}
|
|||
|
{$POINTERMATH ON}
|
|||
|
// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
|
|||
|
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
|
|||
|
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
|
|||
|
program cv_Save;
|
|||
|
|
|||
|
{$R *.res}
|
|||
|
|
|||
|
uses
|
|||
|
System.SysUtils,
|
|||
|
Core.types_c in '..\..\..\include\<5C>ore\Core.types_c.pas',
|
|||
|
core_c in '..\..\..\include\<5C>ore\core_c.pas',
|
|||
|
highgui_c in '..\..\..\include\highgui\highgui_c.pas',
|
|||
|
uLibName in '..\..\..\include\uLibName.pas',
|
|||
|
types_c in '..\..\..\include\<5C>ore\types_c.pas';
|
|||
|
|
|||
|
Const
|
|||
|
kernet_filename = 'result\kernel.xml';
|
|||
|
|
|||
|
Var
|
|||
|
kernel: array [0 .. 8] of Single;
|
|||
|
kernel_matrix: TCvMat;
|
|||
|
i: Integer;
|
|||
|
j: Integer;
|
|||
|
matrix: pCvMat;
|
|||
|
ptr: pSingle;
|
|||
|
fs: pCvFileStorage;
|
|||
|
frame_count: Integer;
|
|||
|
s: pCvSeq;
|
|||
|
frame_width: Integer;
|
|||
|
frame_height: Integer;
|
|||
|
color_cvt_matrix: pCvMat;
|
|||
|
|
|||
|
begin
|
|||
|
try
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
kernel[0] := 1;
|
|||
|
kernel[1] := 0;
|
|||
|
kernel[2] := 0;
|
|||
|
kernel[3] := 0;
|
|||
|
kernel[4] := 2;
|
|||
|
kernel[5] := 0;
|
|||
|
kernel[6] := 0;
|
|||
|
kernel[7] := 0;
|
|||
|
kernel[8] := 3;
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
kernel_matrix := cvMat(3, 3, CV_32FC1, @kernel);
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> XML-<2D><><EFBFBD><EFBFBD>
|
|||
|
cvSave(kernet_filename, @kernel_matrix);
|
|||
|
// <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> XML-<2D><><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
matrix := pCvMat(cvLoad(kernet_filename));
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// 1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CV_MAT_ELEM
|
|||
|
for i := 0 to matrix^.rows - 1 do
|
|||
|
begin
|
|||
|
for j := 0 to matrix^.cols - 1 do
|
|||
|
Write(Format('%.0f ', [pSingle(CV_MAT_ELEM(matrix^, CV_32FC1, i, j))^]));
|
|||
|
Writeln;
|
|||
|
end;
|
|||
|
Writeln;
|
|||
|
|
|||
|
// 2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> cvGet2D()
|
|||
|
// cvGetReal2D() <20><><EFBFBD> CV_64FC1
|
|||
|
for i := 0 to matrix^.rows - 1 do
|
|||
|
begin
|
|||
|
for j := 0 to matrix^.cols - 1 do
|
|||
|
Write(Format('%.0f ', [cvGet2D(matrix, i, j).val[0]]));
|
|||
|
Writeln;
|
|||
|
end;
|
|||
|
Writeln('-----');
|
|||
|
|
|||
|
// 3 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
for i := 0 to matrix^.rows - 1 do
|
|||
|
begin
|
|||
|
ptr := pSingle((Integer(matrix^.data) + i * matrix^.step));
|
|||
|
for j := 0 to matrix^.cols - 1 do
|
|||
|
Write(Format('%.0f ', [ptr[j]]));
|
|||
|
Writeln;
|
|||
|
end;
|
|||
|
Writeln('-----');
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
cvReleaseMat(matrix);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> XML
|
|||
|
Writeln('Example 3_19 Reading in cfg.xml');
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
fs := cvOpenFileStorage('resource\cfg.xml', 0, CV_STORAGE_READ);
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
frame_count := cvReadIntByName(fs, 0, 'frame_count', 5 { <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> } );
|
|||
|
s := cvGetFileNodeByName(fs, 0, 'frame_size')^.seq;
|
|||
|
frame_width := cvReadInt(pCvFileNode(cvGetSeqElem(s, 0)));
|
|||
|
frame_height := cvReadInt(pCvFileNode(cvGetSeqElem(s, 1)));
|
|||
|
color_cvt_matrix := pCvMat(cvRead(fs, 0));
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
WriteLn(Format('frame_count=%d, frame_width=%d, frame_height=%d',[frame_count,frame_width,frame_height]));
|
|||
|
|
|||
|
cvReleaseFileStorage(fs);
|
|||
|
Writeln('Press <Enter>');
|
|||
|
Readln;
|
|||
|
except
|
|||
|
on E: Exception do
|
|||
|
Writeln(E.ClassName, ': ', E.Message);
|
|||
|
end;
|
|||
|
|
|||
|
end.
|