mirror of
https://github.com/Laex/Delphi-OpenCV.git
synced 2024-11-18 01:05:53 +01:00
a016c463c5
Signed-off-by: Laentir Valetov <laex@bk.ru>
133 lines
3.8 KiB
ObjectPascal
133 lines
3.8 KiB
ObjectPascal
|
||
//*****************************************************************
|
||
// Delphi-OpenCV Demo
|
||
// Copyright (C) 2013 Project Delphi-OpenCV
|
||
// ****************************************************************
|
||
// Contributor:
|
||
// Laentir Valetov
|
||
// email:laex@bk.ru
|
||
// ****************************************************************
|
||
// You may retrieve the latest version of this file at the GitHub,
|
||
// located at git://github.com/Laex/Delphi-OpenCV.git
|
||
// ****************************************************************
|
||
// The contents of this file are used with permission, subject to
|
||
// the Mozilla Public License Version 1.1 (the "License"); you may
|
||
// not use this file except in compliance with the License. You may
|
||
// obtain a copy of the License at
|
||
// http://www.mozilla.org/MPL/MPL-1_1Final.html
|
||
//
|
||
// Software distributed under the License is distributed on an
|
||
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||
// implied. See the License for the specific language governing
|
||
// rights and limitations under the License.
|
||
//*******************************************************************
|
||
|
||
program cv_Save;
|
||
|
||
{$APPTYPE CONSOLE}
|
||
{$POINTERMATH ON}
|
||
|
||
{$R *.res}
|
||
|
||
uses
|
||
System.SysUtils,
|
||
ocv.highgui_c,
|
||
ocv.core_c,
|
||
ocv.core.types_c,
|
||
ocv.imgproc_c,
|
||
ocv.imgproc.types_c,
|
||
uResourcePaths;
|
||
|
||
const
|
||
kernet_filename = cResourceResult + '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
|
||
// ìcccèâ, cîäåðæàùèé äàííûå ìàòðèöû
|
||
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;
|
||
// cîçäà¸ì ìàòðèöó
|
||
kernel_matrix := cvMat(3, 3, CV_32FC1, @kernel);
|
||
// cîõðàíÿåì ìàòðèöó â XML-ôàéë
|
||
cvSave(kernet_filename, @kernel_matrix);
|
||
// à òåïåðü çàãðóçèì äàííûå èç XML-ôàéëà
|
||
matrix := pCvMat(cvLoad(kernet_filename));
|
||
// ïîêàæåì cîäåðæèìîå ìàòðèöû
|
||
// 1 âàðèàíò: c ècïîëüçîâàíèåì ìàêðîcà 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^, SizeOf(single), i, j))^]));
|
||
Writeln;
|
||
end;
|
||
Writeln;
|
||
|
||
// 2 âàðèàíò: c ècïîëüçîâàíèåì cvGet2D()
|
||
// cvGetReal2D() äëÿ 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 âàðèàíò: ïðÿìîé äîcòóï ê ýëåìåíòàì
|
||
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('-----');
|
||
|
||
// îcâîáîæäàåì ðåcóðcû
|
||
cvReleaseMat(matrix);
|
||
|
||
// ×òåíèå XML
|
||
Writeln('Example 3_19 Reading in cfg.xml');
|
||
|
||
// îòêðûâàåì ôàéë äëÿ ÷òåíèÿ
|
||
fs := cvOpenFileStorage(cResourceMedia + 'cfg.xml', 0, CV_STORAGE_READ);
|
||
// c÷èòûâàåì çíà÷åíèÿ
|
||
frame_count := cvReadIntByName(fs, 0, 'frame_count', 5 { çíà÷åíèå ïî-óìîë÷àíèþ } );
|
||
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));
|
||
|
||
// ïîêàçûâàåì
|
||
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.
|