Loading image from memory stream / buffer
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?
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
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 :)
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;
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.