Announcing Xojo OpenCVC - OpenCV 4.5 for Xojo

Last year we began work on porting OpenCV 4.5 to Xojo. This first involved the creation of a plain-C interface to OpenCV, which we have now open sourced, though it still requires some work to complete.

Today I’m open sourcing Xojo OpenCV-C. This is a Xojo project that wraps OpenCV-C, creating a Xojo Native interface to OpenCV. It is mostly complete, though there are some remaining issues that we just haven’t had time to deal with. I’m hoping someone here will be able to help out and make this a reality. Other obligations are keeping me from focusing on this, but a lot of hard work has been put into it so far.

If you’re able to help on either or both of these projects, please dive in!


Looks pretty cool!

1 Like

When I try to open the project in Xojo 2022r1.1 it complains that the folder “macStuff” can’t be found.

You can ignore that, or make a “macstuff” folder in your project folder.

Unfortunately, when trying to use OpenCV in my app I only get hard crashes.


dim theCVMat as openCV.CVCMat = openCV.Codecs.imDecode(MimeData, openCV.ImReadModes.Unchanged)
dim scaledSize As New openCV.CVCSize(myPreviewSize, myPreviewSize)
dim theCVMatNew as new openCV.CVCMat
openCV.imgProc.CVCresize(theCVMat, theCVMatNew, scaledSize, 0.0, 0.0, openCV.InterpolationFlags.Area)
PreviewPic = theCVMat.image

Crash log with Xojo 20221 on macOS Ventura:

Crashed Thread: 23

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000

Error Formulating Crash Report:
dyld_process_snapshot_create_for_process failed with 5

Kernel Triage:
VM - Fault hit memory shortage
VM - Fault hit memory shortage
VM - Fault hit memory shortage
VM - Fault hit memory shortage
VM - Fault hit memory shortage

Thread 23 Crashed:
0 ??? 0x7ff8ab63a954 ???
1 libsystem_kernel.dylib 0x7ff81c4a633e __pthread_kill + 10
2 libsystem_pthread.dylib 0x7ff81c4de1ef pthread_kill + 263
3 libsystem_c.dylib 0x7ff81c427cb8 abort + 123
4 libc++abi.dylib 0x7ff81c498082 abort_message + 241
5 libc++abi.dylib 0x7ff81c489225 demangling_terminate_handler() + 242
6 libobjc.A.dylib 0x7ff81c220568 _objc_terminate() + 104
7 libc++abi.dylib 0x7ff81c4974a5 std::__terminate(void ()()) + 8
8 libc++abi.dylib 0x7ff81c499d05 __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception
) + 27
9 libc++abi.dylib 0x7ff81c499ccc __cxa_throw + 116
10 libOpenCVC.dylib 0x153095173 cv::error(cv::Exception const&) + 243
11 libOpenCVC.dylib 0x153094b04 cv::error(int, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, char const*, char const*, int) + 308
12 libOpenCVC.dylib 0x1533663e8 cv::resize(cv::_InputArray const&, cv::OutputArray const&, cv::Size, double, double, int) + 5864
13 libOpenCVC.dylib 0x152c935b3 CVCresize + 115
14 Mail Archiver X.debug 0x103632bbf openCV.imgProc.CVCresize%%o<openCV.CVCMat>o<openCV.CVCMat>o<openCV.CVCSize>f8f8i8<openCV.InterpolationFlags> + 943 (/openCV:1168)
15 Mail Archiver X.debug 0x1041d51f2 MimeImagePreview.MakeImagePreview%%o + 3010 (/MimeImagePreview:54)
16 Mail Archiver X.debug 0x1041d32a2 MimeImagePreview.Constructor%%osss&s + 1394 (/MimeImagePreview:16)
17 Mail Archiver X.debug 0x10407baf5 MimeHtmlPreview.MakeHtmlPreview%%o + 7909 (/MimeHtmlPreview:151)
18 Mail Archiver X.debug 0x104074329 MimeHtmlPreview.Constructor%%osssb&s&s + 1369 (/MimeHtmlPreview:12)
19 Mail Archiver X.debug 0x1036fef15 MimeAttachment.getHtmlPreview%s%ob + 2021 (/MimeAttachment:287)
20 Mail Archiver X.debug 0x1036a0f96 MimeParser.parseChildPart%%ooo + 19238 (/MimeParser:443)
21 Mail Archiver X.debug 0x103698142 MimeParser.parseMixed%%oo + 1906 (/MimeParser:281)
22 Mail Archiver X.debug 0x1036915db MimeParser.parseMime%%oo + 1579 (/MimeParser:111)
23 Mail Archiver X.debug 0x1036947db MimeParser.parseAlternative%%oo + 6011 (/MimeParser:168)
24 Mail Archiver X.debug 0x10369149e MimeParser.parseMime%%oo + 1262 (/MimeParser:106)
25 Mail Archiver X.debug 0x10368eafe MimeParser.execute%%o + 5150 (/MimeParser:54)
26 Mail Archiver X.debug 0x10368cf69 MimeParser.Constructor%%osbA1o + 1465 (/MimeParser:16)
27 Mail Archiver X.debug 0x10376984f MailParser.ParseMime%%o + 2959 (/MailParser:926)
28 Mail Archiver X.debug 0x1037346f2 MailParser.parse%i8%o + 9250 (/MailParser:91)
29 Mail Archiver X.debug 0x1045cb1cf ArchiveThread.Archive%%o + 12319 (/ArchiveThread:179)
30 Mail Archiver X.debug 0x1045c082b ArchiveThread.Event_Run%%o + 235 (/ArchiveThread:6)
31 XojoFramework 0x115bc64cf 0x115950000 + 2581711
32 XojoFramework 0x115a860e8 0x115950000 + 1269992
33 libsystem_pthread.dylib 0x7ff81c4de4d1 _pthread_start + 125
34 libsystem_pthread.dylib 0x7ff81c4d9eef thread_start + 15

I made an example: .

Load an image, then click on the resize button. Tested on High Sierra and Ventura (why do I always type Ventuna???).

@Perry_Paolantonio : do you have any idea on how to fix the crash?

Sorry - I don’t. We’re in the middle of buying a new office and I’m up to my neck in wrangling lawyers, realtors, bankers, insurers, movers and also doing client work, while packing up 20 years of accumulated detritus.

I’d start with the xojo test application that’s in the github repo. Does that work? Most functions in that app should be fine, though some of the newer ones were still experimental and may require some additions to OpenCV-C. If not, it would suggest either an issue with newer versions of Xojo or perhaps with the dylib and the OS? I believe we tested on Big Sur and Catalina primarily, on Xojo 2021 2.1.

I don’t expect I’ll get a chance to do much of anything on this until at least September, given all we’re doing right now. If there is a bug though, and someone figures it out, feel free to contribute a fix!

My code is only a couple of lines and I tested on High Sierra and Ventura. Have lots of fun with your wrangling. Such is life.

I had a minute during lunch and took a quick look at your version of the project. I’m wondering if it has something to do with your mime encoded image? I don’t think we’ve tested that specifically, and I’m not even 100% sure how (or if) OpenCV would know what to do with that. I don’t really have any experience with mime encoded images, so I don’t know if there’s something there that might be tripping things up. All our testing was on “normal” image files. Perhaps if the mime-encoded file is converted to something like a bitmap first?

I’m also on 2021 r2.1 on this machine, so I get the usual errors about yours being made in a newer version of Xojo. So I wouldn’t expect the project to run on this version, but I did glance at the code and that was the first thing that stuck out to me.

Thanks for taking the time.

Both CGImageSourceMBS and GMBlobMBS cope fine with the data. I just did a Base64Encoding with the data to copy-and-paste the data from my project. Code for CGImageSourceMBS:

dim options as new Dictionary
options.Value(CGImageSourceMBS.kCGImageSourceThumbnailMaxPixelSize) = myPreviewSize
options.Value(CGImageSourceMBS.kCGImageSourceCreateThumbnailFromImageIfAbsent) = true
options.Value(CGImageSourceMBS.kCGImageSourceCreateThumbnailWithTransform) = True

dim theCGImage as CGImageMBS = CGImageSourceMBS.CreateThumbnailMT(MimeData, 0, options)

Screenshot of data in debugger:

The data is just a measly 1-pixel gif.

I made an example: .

seems like not working anymore, thanks

I’ve re-uploaded the project.

1 Like

You can delete the reference to the file. It’s a left over from the original OpenCV example.

1 Like

OpenCV 4.5+ runs on Apple Silicon M1 computers. You just need to compile the OpenCV-C dynamic library. Great Job:)

1 Like