Coder Social home page Coder Social logo

gidesa / ocvwrapper46 Goto Github PK

View Code? Open in Web Editor NEW
48.0 48.0 9.0 115.01 MB

Opencv C++ API wrapper for Delphi, Lazarus/Freepascal and C - for Opencv v 4.6

License: GNU General Public License v3.0

Pascal 44.78% C++ 50.29% C 3.99% Makefile 0.03% Shell 0.08% CSS 0.07% JavaScript 0.50% HTML 0.26%

ocvwrapper46's People

Contributors

gidesa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ocvwrapper46's Issues

Differences from “dnnObjectDetection” darknet training results

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?

Compiler Errors

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.

Compiler warnings

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.

error about lazarus_component

unOCVImage.pas(242,15) Error: Identifier not found "CV_8UC4"
unOCVImage.pas(250,15) Error: Identifier not found "CV_32SC4"
....

dnnObjectDetection Hanges

Hi,

Please note that dnnObjectDetection (64 bit) hangs at pCvdnn_NetforwardV4(net, vecOut, outNames); instruction

Best regards

Example usage of ONNX in project documentation

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.

Delphi or Lazarus integration

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 !

Error installing component

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.

Problem with imencode

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.

TOcvDNNFaceRecognizer Compare two PCvMat_t face image

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.

Question: How to load a pCvMat from a TStream

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

Add step to Mat constructor when dataptr is not null

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.

Enhancement: Delayed loading DLL & Memory Management redirection

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.

numpy

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)

Face recognition exception

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:

image

at CvModelYN := pCvFaceDetectorYN_create(@model,@config,InputSize);

Best regards

Static vs Dynamic DLL loading

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.