COII: Which OpenCV functions secretly change COI?

I’m using OpenCV (in C# through Emgu). When I run my (~10k lines) code with MaxDegreeOfParallelism=1, everything’s great. When I run truly in parallel, I get an OpenCV Exception that Convolution (and a few other functions) don’t support COI. :frowning:

Apparently, something’s changing an Image[Gray,byte]'s COI to 1, doing some work, and then changing it back to 0. In serial, that’s fine. In parallel, it breaks other OpenCV functions that crash when COI≠0. I didn’t even know about COI until today, so it must be some prebuilt function in OpenCV. (Like how img.Copy subtly uses img.ROI.)

I replaced every local “img.Method(” with “img.SafeMethod(”, where I wrote the Safe one to check COI, lock img, do actual Method, unlock img, and check COI again. I replaced tons of { .CountNonzero, .Copy, .Or, .Not, .Threshold, .Sub, .And, . Convolution, .Xor }. It still breaks (only in parallel). :frowning:

I clearly missed an img.Method somewhere, since something’s changing an img.COI (while ignoring the img lock). Any idea which OpenCV methods change COI back and forth, so I can lock while they work?

Thanks for your help.
-Sam

Edit: Here’s more Info on COI. It’s an inherent property of images in OpenCV. Here’s the exception: OpenCV: cv::Error Namespace Reference

welcome.

what is “COI”? is that some C# term?

edit: I looked. it means “channel of interest”. I see some signs that there is some fairly internal function that’s there to be glue between C and C++. I’ve never encountered it before.

I’d say this is emgu’s “fault” for using this feature or you’re using some weird and unusual functions.

edit: I’d even say this is an emgu-only feature or emgu uses weird data structures that aren’t OpenCV-native (such as IplImage).

either way, I’d recommend NOT working concurrently on different channels of the same Mat. this does HORRIBLE things to your CPU cores’ caches.

COI is definitely an OpenCV thing, not just Emgu. Basic C Structures and Operations — OpenCV 2.4.13.7 documentation
Sorry I wasn’t clear: I’m certainly not setting COI myself anywhere. Some other, prebuilt OpenCV function is momentarily editing it itself and then putting it back. We normally wouldn’t notice, but in parallel it’s causing conflicts.
Edited the OP for more COI info.

that’s referencing an IplImage type, which is VERY legacy. that’s also the C API that existed in v2.4 and has been deprecated since and removed over the years.

nothing these days should ever touch an IplImage. in fact I’d say it MUST NOT be done.

I’ve looked for data structures that have anything relating to a “COI”. couldn’t find that.

the fields of a cv::Mat are documented. there’s nothing that has this functionality.

I’d like to know exemplary functions and data structures you use that cause this… also if there’s an error message and what it is and where it comes from.

you should definitely talk to Emgu people about this. this forum doesn’t support Emgu even though some well-meaning responses happen sometimes. Emgu isn’t just a wrapper around current OpenCV. a lot more happens there. and maybe it involves calling C APIs that should never have been used in the first place. your first instinct should be to look at Emgu for blame, not OpenCV.

you must be mistaken. look: Search · BadCOI · GitHub one result, a definition that hasn’t been removed for API compatibility reasons. it is used nowhere.

1 Like

Very smart. That makes a lot of sense. Thanks for your help.

I see now that my top two messages were flagged as spam! I’m sorry, I really didn’t mean to break any rules. Was it that I referenced [an OpenCV c# wrapper that shall not be named]?

I have no idea what’s going on there. they were certainly not flagged yet when I responded earlier. I’d expect a spam filter to act immediately, so it must be someone’s deliberate action.

you gotta understand, OpenCV is primarily controlled by Intel. I think they run the forum, or have it run for them. support for third party wrappers should always be given by that third party first, not the upstream project, because they did something non-trivial (a wrapper is non-trivial) vs. resale/import/rebranding. that goes for everything in open source, also in life. asking for Emgu around here is probably considered off-topic although I wouldn’t mind it… but there aren’t any people around here who work on Emgu or have any great expertise with it, so any support would amount to “please go talk to them”.

1 Like

Gotcha. Sorry about that. I had considered whether it was just another Emgu problem, but thought it was OpenCV-related when I found the red-herring links above :slight_smile:

Thanks for all your help.

@Sam_Greenberg @crackwitz in previous forum emgu was not authorized only official binding. It was written in the faq. Why ? I don’t know.

Now there is nothing in faq so I don’t understand why your post is flagged.
I’m moderator as @crackwitz but i don’t know how unflagged.
There is a problem faq must be changed or your post must be unflagged !

1 Like