Delphi-OpenCV icon indicating copy to clipboard operation
Delphi-OpenCV copied to clipboard

Loading image from memory stream / buffer

Open HristoMarkow opened this issue 1 year ago • 4 comments

Hi,

I've looked at OpenCV documentation ImDecode and according it should be used two functions C++: Mat imdecode(InputArray buf, int flags) C: IplImage* cvDecodeImage(const CvMat* buf, int iscolor=CV_LOAD_IMAGE_COLOR)

cvDecodeImage is defined function cvDecodeImage(const buf: pCvMat; iscolor: Integer = CV_LOAD_IMAGE_COLOR): pIplImage; cdecl; in ocv.highgui_c.pas but the first function isn't. I've looked in all DLL files, but didn't find such exported function.

Any ideas?

HristoMarkow avatar Mar 02 '25 10:03 HristoMarkow

There will be no functions C++: Mat imdecode(InputArray buf, int flags) C++: Mat imdecode(InputArray buf, int flags, Mat* dst) since this is C++ and uses C++ classes Use C: IplImage* cvDecodeImage(const CvMat* buf, int iscolor=CV_LOAD_IMAGE_COLOR) or C: CvMat* cvDecodeImageM(const CvMat* buf, int iscolor=CV_LOAD_IMAGE_COLOR)

...If I understood the problem correctly

Laex avatar Mar 02 '25 15:03 Laex

CvMat is a structure of some data used in OpenCV, but PNG or JPEG image isn't in same format. I wish to import image from MemoryStream which is captured from screen and I haven't save in file to the disk. I'm looking for something like function cvLoadImageFromStream(const S : TStream; iscolor: Integer = CV_LOAD_IMAGE_UNCHANGED): pIplImage; cdecl; external highgui_lib{$IFDEF DELAYEDLOADLIB} delayed{$ENDIF}; or load from memory buffer :)

HristoMarkow avatar Mar 03 '25 08:03 HristoMarkow

Basic idea, code not tested

function cvLoadImageFromStream(const S: TStream): pIplImage;
begin
  Var
    G: TPicture := TPicture.Create;
  try
    G.LoadFromStream(S);
    Result := BitmapToIplImage(G.Bitmap); // defined in ocv.utils
  finally
    G.Free;
  end;
end;

Laex avatar Mar 04 '25 06:03 Laex

Thanks a lot. B := TBitmap.Create; try // src := cvLoadImage({cResourceMedia}'baboon.jpg', CV_LOAD_IMAGE_ANYCOLOR OR CV_LOAD_IMAGE_ANYDEPTH); B.LoadFromFile('baboon.bmp'); src := BitmapToIplImage(B); ............................ finally B.Free; end; I will try it.

HristoMarkow avatar Mar 04 '25 17:03 HristoMarkow