We’ve hired someone to create a C interface to OpenCV 4.5.2, since the built-in C API is now deprecated. He has provided an initial test DLL and Dylib, and some simple C code based on python scripts I sent him that I had been working with: open, resize, change the color space, run canny edge detection.
I’m getting a little outside of my comfort zone here and keep getting tripped up on what’s probably something fairly simple. Right now I just want to test that his code loads images into Xojo. Open CV uses the CVMat struct for passing around image data. So the code I’ve been given requires me to create a Mat (basically an empty image), which I can then fill with the results of OpenCV function calls, and then to destroy that Mat when I’m done.
I’ve created a Mat class, with external methods for CVMatCreate, CVMatFree, CVMatHeight, CVMatWidth, CVResize, CVimread (from the C DLL he made). Corresponding internal methods are createMat, freeMat, getHeight, getWidth, resize, loadImage, respectively.
All of this is working - loading up the DLL, no errors calling the OpenCV functions. As a testbed, he provided a simple C application that does the same thing as my python scripts. So the python code:
img = cv.imread("Test-Pattern.tif")
becomes (in C):
CVMat image = CVimread("Test-Pattern.tif");
if (image != NULL) {
printf("Image loaded.\n");
CVMatFree(image);
} else {
printf("Error loading image.\n");
return 0;
}
Where I’m getting confused is with the creation of the CVMat struct, in Xojo. The C code for that is:
(from grdOpenCV.cpp)
CVMat CVMatCreate(void)
{
try {
cv::Mat *mat = new cv::Mat();
return (CVMat)mat;
} catch (...) { }
return NULL;
}
(from grdOpenCV.h):
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
// exported opencv types
typedef void* CVMat;
// exported opencv type functions
CVMat CVMatCreate(void);
How should I go about setting this up in Xojo? Based on my reading of the OpenCV docs linked to above, a CVMat can become a pretty complex beast, that’s sometimes very simple, and sometimes not at all. I’d be happy to PM a link to the project file with the C Code and DLL if someone is able to help me puzzle through this. Once I get past this hurdle, the rest seems to be fairly straightforward. I just can’t seem to wrap my head around this one.
Thanks