gidesa / ocvwrapper46 Goto Github PK
View Code? Open in Web Editor NEWOpencv C++ API wrapper for Delphi, Lazarus/Freepascal and C - for Opencv v 4.6
License: GNU General Public License v3.0
Opencv C++ API wrapper for Delphi, Lazarus/Freepascal and C - for Opencv v 4.6
License: GNU General Public License v3.0
hello
I am trying to use the yolov4 weights file learned with darknet, but the learning results from darknet are different from the results detected by the “dnnObjectDetection” sample program.
I tried modifying the image size and Threshold Value global variables, but they are still the same.
(The image size in the "dnnObjectDetection" sample program is 416, so it has been changed to 416 and re-training is in progress...)
Do you know the solution?
Hello,
Please note these errors generated when compiling dnnObjectDetection project (64 bit)
dnnObjectDetection.dpr
[dcc64 Error] frmDnnObjectDetection.pas(53): E2003 Undeclared identifier: 'PCvdnn_Net_t'
[dcc64 Error] frmDnnObjectDetection.pas(101): E2003 Undeclared identifier: 'PCvvector_Rect2d'
[dcc64 Error] frmDnnObjectDetection.pas(112): E2003 Undeclared identifier: 'PCvRect2d_t'
[dcc64 Error] frmDnnObjectDetection.pas(114): E2003 Undeclared identifier: 'CvRect2dS'
[dcc64 Error] frmDnnObjectDetection.pas(156): E2003 Undeclared identifier: 'pCvdnn_blobFromImage'
[dcc64 Error] frmDnnObjectDetection.pas(157): E2003 Undeclared identifier: 'pCvdnn_NetsetInput'
[dcc64 Error] frmDnnObjectDetection.pas(160): E2003 Undeclared identifier: 'pCvdnn_NetforwardV4'
[dcc64 Error] frmDnnObjectDetection.pas(173): E2010 Incompatible types: 'UInt64' and 'Pointer'
[dcc64 Error] frmDnnObjectDetection.pas(184): E2034 Too many actual parameters
[dcc64 Error] frmDnnObjectDetection.pas(186): E2035 Not enough actual parameters
[dcc64 Warning] frmDnnObjectDetection.pas(207): W1073 Combining signed type and unsigned 64-bit type - treated as an unsigned type
[dcc64 Error] frmDnnObjectDetection.pas(211): E2003 Undeclared identifier: 'pCvVectorRect2dCreate'
[dcc64 Error] frmDnnObjectDetection.pas(216): E2003 Undeclared identifier: 'CvRect2d_'
[dcc64 Error] frmDnnObjectDetection.pas(217): E2003 Undeclared identifier: 'pCvVectorRect2dSet'
[dcc64 Error] frmDnnObjectDetection.pas(222): E2003 Undeclared identifier: 'pCvdnn_NMSBoxes'
[dcc64 Error] frmDnnObjectDetection.pas(238): E2035 Not enough actual parameters
[dcc64 Error] frmDnnObjectDetection.pas(243): E2035 Not enough actual parameters
[dcc64 Error] frmDnnObjectDetection.pas(258): E2003 Undeclared identifier: 'pCvVectorRect2dDelete'
[dcc64 Error] frmDnnObjectDetection.pas(294): E2003 Undeclared identifier: 'pCvdnn_readNetFromDarknet'
[dcc64 Error] frmDnnObjectDetection.pas(295): E2003 Undeclared identifier: 'pCvdnn_NetsetPreferableBackend'
[dcc64 Error] frmDnnObjectDetection.pas(295): E2003 Undeclared identifier: 'DNN_BACKEND_OPENCV'
[dcc64 Error] frmDnnObjectDetection.pas(296): E2003 Undeclared identifier: 'pCvdnn_NetsetPreferableTarget'
[dcc64 Error] frmDnnObjectDetection.pas(296): E2003 Undeclared identifier: 'DNN_TARGET_CPU'
[dcc64 Error] frmDnnObjectDetection.pas(297): E2003 Undeclared identifier: 'pCvocl_haveOpenCL'
[dcc64 Error] frmDnnObjectDetection.pas(299): E2003 Undeclared identifier: 'pCvocl_setUseOpenCL'
[dcc64 Error] frmDnnObjectDetection.pas(300): E2003 Undeclared identifier: 'DNN_TARGET_OPENCL'
[dcc64 Error] frmDnnObjectDetection.pas(302): E2003 Undeclared identifier: 'pCvdnn_NetgetUnconnectedOutLayersNames'
[dcc64 Fatal Error] dnnObjectDetection.dpr(8): F2063 Could not compile used unit 'frmDnnObjectDetection.pas'
Best regards.
Hi,
Please note these compiler warnings:
[dcc64 Warning] unOpenCVDelphi46.pas(263): W1036 Variable 'mt' might not have been initialized
[dcc64 Warning] unOpenCVDelphi46.pas(786): W1073 Combining signed type and unsigned 64-bit type - treated as an unsigned type
[dcc64 Warning] unOpenCVDelphi46.pas(834): W1036 Variable 'vecNmsIndex' might not have been initialized
[dcc64 Warning] unOpenCVDelphi46.pas(832): W1036 Variable 'vecBoxes' might not have been initialized
[dcc64 Warning] unOpenCVDelphi46.pas(833): W1036 Variable 'vecScores' might not have been initialized
[dcc64 Warning] unOpenCVDelphi46.pas(840): W1036 Variable 'classIdPoint' might not have been initialized
[dcc64 Warning] unOpenCVDelphi46.pas(830): W1036 Variable 'img' might not have been initialized
Best regards.
unOCVImage.pas(242,15) Error: Identifier not found "CV_8UC4"
unOCVImage.pas(250,15) Error: Identifier not found "CV_32SC4"
....
Hi,
Please note that dnnObjectDetection (64 bit) hangs at pCvdnn_NetforwardV4(net, vecOut, outNames); instruction
Best regards
Hello, I was exploring the project's documentation and I noticed that there isn't a clear example of how to use ONNX in the project. I think it would be helpful to have a tutorial or code example that demonstrates how to incorporate ONNX into the project's workflow. ONNX is a popular format for representing deep learning models, and I believe it would be valuable to show users how to use it in the context of this project. Would it be possible to add such an example to the documentation? Thank you for your time and consideration.
I can't tell you how happy I was about the co-implimentation for lazarus. Thank you so much !
The installation on Windows x64 was not without problems, but after I downloaded the appropriate 64bit dll's and copied them into the installation directory, everything was smooth.
A big problem I personally have is the interaction with Delphi respectively Lazarus. All examples show more or less raw functionality of openCV in its own framework.
For example: here the image is shown as a function of openCV in a new openCV-window:
cvstr.pstr:=PAnsiChar(AnsiString('result'));
pCvimshow(@cvstr, img1);
but how can one pass bitmaps from VLC / LCL to openCV and how to show the results in VLC / LCL bitmaps after processing ?
More examples about the interaction of the wrapper with Delphi or Lazarus would be very helpful …
Thanks a million !
I'm trying to install the test components in Delphi 11 and it's giving me an error during installation, the compilation passes without any problems. I put the following DLLs in the source folder of the pkocvWrapComp project:
ocvCPPWrapper46.dll
opencv_videoio_ffmpeg460.dll
opencv_world460.dll
opencv_world460d.dll
All in 32bit versions, the error that is giving is:
The specified module could not be found.
Hello again, I'm trying to save the output image to memory instead of a file, but I get violation error:
var
params: PCvvector_int;
buf: PCvVector_uchar;
...
pCvMatConvertTo(colorImg, colorImg, CV_8U, 255);
cvstr.pstr:= '.jpg';
params:= pCvVectorintCreate(2);
pCvVectorIntSet(params, 0, 100);
pCvVectorIntSet(params, 0, Integer(IMWRITE_JPEG_QUALITY));
pcvImEncode(@cvstr, colorImg, buf, params);
Maybe I have to initialize buf any way? Or params is bad initialized? (swapping the two params is not helping, although maybe it must be done). Thanks for any help.
Just written this I've realized that both vector sets were with '0' as second argument, but replacing the second one with '1' doesn't help neither.
Hi,
I would compare only two PCvMat_t face images generating cos_score & L2_score scores without using the TOCVImage component.
Would you please provide an example illustration this request?
Is it possible to use the OpenCVWrapper to compare two bio-metric fingerprints as it's done for Faces?
Best regards.
Thank you for this great implementation! I am new to OpenCV so my apologies up front if my question is obvious.
I am trying to load a JPG image from a TStream. Your code samples all show how to load an image from a file, but I cannot figure out how to load an image from a stream (eg a TFileStream or TMemoryStream).
I believe that I should use the openCV function imageMat(imageData) for that.
Is this method available in your wrapper? Or if not, is there a recommended way or a sample code to load an image from a stream?
(note: I am using FPC 3.2.2/Lazarus 2.2)
Thank you
Hello, if you see in opencv documentation, between all the Mat constructors there are three with a "Data" parameter, those three constructors add at the end a "Step" parameter. I think therefore in:
function pCvMatCreate(const ndims: Integer; const dims: PInteger; const mtype: integer; dataptr: UInt64 = 0): PCvMat_t; cdecl;
It should be a last "Step" parameter also.
Hi,
Would you please modify static loading DLL using delay loading mechanism?
function pCvRedirectException; external ocvWrapper name 'pCvRedirectException';
change to
function pCvRedirectException; external ocvWrapper name 'pCvRedirectException' delayed;
Any routines to redirect calls related to allocation and freeing Memory to detect Memory Leaks? The old implementation integrates this Manager:
procedure cvSetMemoryManager(alloc_func: TCvAllocFunc = nil; free_func: TCvFreeFunc = nil; userdata: Pointer = nil); cdecl; external core_lib{$IFDEF DELAYEDLOADLIB} delayed{$ENDIF};
Best regards.
Hi,
Would you please integrate Face Landmark Detection into your invaluable library?
Best regards.
Here is a Python code snippet that uses the numpy library.
Is it possible to rewrite it as a Delphi program using the
ocvWrapper46 library?
kernel = numpy.array([
[0, -1, 0],
[-1, 5, -1],
[0, -1, 0]
])
bw = cv.filter2D(bw, -1, kernel)
some unit use windows in interface section
CommThread.pas has following code
interface
uses
{$IFDEF LCL}
Windows, Classes, SysUtils, SyncObjs, lazCollections;
{$ELSE}
Hi,
Model an Recognizer downloaded from:
https://github.com/opencv/opencv_zoo/tree/master/models/face_detection_yunet
and using this code:
function TOpenCV.RecognizeFace(Face:TBytes;Templates:array of TBytes;out &Label:Integer):Double;
const
DetectModel = 'face_detection_yunet_2021dec.onnx';
RecognizeModel = 'face_recognition_sface_2021dec.onnx';
var
Model ,
Config : CvString_t;
CvModelYN : PCvPtr_FaceDetectorYN;
CvModel : PCvFaceDetectorYN_t;
InputSize : PCvSize_t;
FaceImage ,
FaceMat ,
FaceFeature : PCvMat_t;
Template : TBytes;
TemplateImage ,
TemplateMat ,
TemplateFeature : PCvMat_t;
CvRecognizerFS : PCvPtr_FaceRecognizerSF;
CvRecognizer : PCvFaceRecognizerSF_t;
begin
Result := 0;
FaceMat := nil;
FaceFeature := nil;
TemplateMat := nil;
TemplateFeature := nil;
CvRecognizerFS := nil;
CvRecognizer := nil;
CvModel := nil;
InitRecord(Model,SizeOf(Model));
InitRecord(Config,SizeOf(Config));
Model.pstr := PAnsiChar(AnsiString(LibrarySearchPath+DetectModel));
Config.pstr := nil;
InputSize := CvSize_(320,320);
try
CvModelYN := pCvFaceDetectorYN_create(@Model,@Config,InputSize);
finally
end;
pCvSizeDelete(InputSize);
if Assigned(CvModelYN) then
begin
CvModel := pCvPtr_FaceDetectorYNConvert(CvModelYN);
FaceImage := LoadMat(Face,[cvGray]);
FaceMat := pCvMatCreateEmpty;
pCvFaceDetectorYNdetect(CvModel,FaceImage,FaceMat);
Template := Templates[0];
TemplateImage := LoadMat(Template,[cvGray]);
TemplateMat := pCvMatCreateEmpty;
pCvFaceDetectorYNdetect(CvModel,TemplateImage,TemplateMat);
Model.pstr := PAnsiChar(AnsiString(LibrarySearchPath+RecognizeModel));
CvRecognizerFS := pCvFaceRecognizerSF_create(@Model,nil);
CvRecognizer := pCvPtr_FaceRecognizerSFConvert(CvRecognizerFS);
FaceFeature := pCvMatCreateEmpty;
TemplateFeature := pCvMatCreateEmpty;
pCvFaceRecognizerSFfeature(CvRecognizer,FaceMat,FaceFeature);
pCvFaceRecognizerSFfeature(CvRecognizer,TemplateMat,TemplateFeature);
Result := pCvFaceRecognizerSFmatch(CvRecognizer,FaceFeature,TemplateFeature);
end;
if Assigned(CvModel) then pCvPtr_FaceDetectorYNDelete(CvModelYN,CvModel);
if Assigned(CvRecognizerFS) then pCvPtr_FaceRecognizerSFDelete(CvRecognizerFS,CvRecognizer);
if Assigned(TemplateFeature) then pCvMatDelete(TemplateFeature);
if Assigned(FaceFeature) then pCvMatDelete(FaceFeature);
if Assigned(TemplateMat) then pCvMatDelete(TemplateMat);
if Assigned(FaceMat) then pCvMatDelete(FaceMat);
end;
an exception is generated:
at CvModelYN := pCvFaceDetectorYN_create(@model,@config,InputSize);
Best regards
Hi,
Please note that when delayed is used for loading DLL an initialization process should only be used after functions/procedures are loaded ; otherwise any attempt to use functions/procedures before DLLs are located (copied to the right location -Directory Path-) will raise an exception.
This code will always fail:
initialization
begin
try
try
pCvRedirectException(@cvexception);
except
Halt(99);
end;
pCvDefaultMat:=pCvMatCreateEmpty();
pCvDefaultSize:=pCvSizeCreate();
pCvDefaultPoint:=pCvPointCreate();
pCvPoint_1_1:=CvPoint_(-1,-1);
pCvDefaultScalar:=pCvScalarCreate();
StringEmpty.pstr:=PAnsiChar('');
pCvStringEmpty:=@StringEmpty;
except
begin
Halt(99);
end;
end;
{$IFDEF FPC}
// For some Opencv functions Freepascal require to set
// Floating Point Unit exception mask, to disable some exceptions generated
// from C++
SetExceptionMask(GetExceptionMask + [exOverflow,exZeroDivide,exInvalidOp]);
{$ENDIF}
This initialization section should be invoked once the DLL path was identified.
It would be better to write an initialization procedure to be called after dynamically load DLLs.
procedure InitOCVWrapper;
begin
try
try
pCvRedirectException(@cvexception);
except
Halt(99);
end;
pCvDefaultMat:=pCvMatCreateEmpty();
pCvDefaultSize:=pCvSizeCreate();
pCvDefaultPoint:=pCvPointCreate();
pCvPoint_1_1:=CvPoint_(-1,-1);
pCvDefaultScalar:=pCvScalarCreate();
StringEmpty.pstr:=PAnsiChar('');
pCvStringEmpty:=@StringEmpty;
except
begin
Halt(99);
end;
end;
{$IFDEF FPC}
// For some Opencv functions Freepascal require to set
// Floating Point Unit exception mask, to disable some exceptions generated
// from C++
SetExceptionMask(GetExceptionMask + [exOverflow,exZeroDivide,exInvalidOp]);
{$ENDIF}
end;
var
OCVApixxx : procedure(..);cdecl;
OCVHandle : THandle;
procedure LoadOCVWrapper;
begin
OCVHandle := LoadLibrary(PChar(ocvWrapper));
@OCVApixxx := GetProcAddress(OCVHandle,OCVApixxx);
InitOCVWrapper;
end;
So the Delayed condition doesn't help! It's simulated to a static loading method.
Best regards.
Hello,
Would this Class be integrated?
https://docs.opencv.org/4.6.0/d4/d93/group__img__hash.html
Best regards.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.