JUCE interfering with OpenCV?


#1

Basically, I’ve made a GUI component in the Jucer and I’m using it’s sliders to process images in an OpenCV window (using OpenCV’s high gui library).

For initial prototyping I just threw the opencv headers in the commented Headers section of my component’s cpp file (generated by the Jucer). Everything worked fine… I had my opencv window and JUCE gui controlling it.

Now, I’m having problems when I try to put the opencv headers in the JUCE component’s header file so I can make all my opencv variables members of my JUCE GUI component.

I get::

/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:168: error: ‘int64’ does not name a type
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:169: error: ‘uint64’ does not name a type
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:273: error: ‘union Cv64suf’ has no member named ‘u’
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:274: error: ‘union Cv64suf’ has no member named ‘u’
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:288: error: ‘union Cv64suf’ has no member named ‘u’
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:289: error: ‘union Cv64suf’ has no member named ‘u’
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h: At global scope:
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:296: error: ‘uint64’ does not name a type
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:298: error: ‘CvRNG’ does not name a type
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:305: error: ‘cvRandInt’ declared as an ‘inline’ variable
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:305: error: ‘CvRNG’ was not declared in this scope
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:305: error: ‘rng’ was not declared in this scope
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:306: error: expected ‘,’ or ‘;’ before ‘{’ token
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:314: error: ‘cvRandReal’ declared as an ‘inline’ variable
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:314: error: ‘CvRNG’ was not declared in this scope
/Developer/SDKs/MacOSX10.5.sdk/Library/Frameworks/OpenCV.framework/Headers/cxtypes.h:314: error: ‘rng’ was not declared in this scope

… and another 20 or so more… all opencv stuff

It seems that JUCE may be somehow interfering with OpenCV. Sorry, but that is about the extent of my compiling vocabulary…

Thoughts on this? Is there a technical term for these kind of errors where one library blocks another?

Thanks!


#2

ah, so both opencv and juce typedef int64. shouldn’t this be namespaced?


#3

The juce one is definitely namespaced.

As a general piece of advice, include other libraries before juce, because my stuff is good at coping with other symbols being defined before it, but other libraries (especially C ones) aren’t always so smart.


#4

I have the same question: how to avoid interfering between OpenCV and Juce? I have started a entirely new Juce Audio-Plugin Project and included the OpenCV header file, but there will be 317 issues with namespace interferences… :frowning:


#6

Meanwhile my VST Plugin works fine with OpenCV. I needed to add the include statements for opencv into my cpp file before I include all other header files.


#7

MarC:

This might have been true in 2007 with OpenCV 1.0. OpenCV 2.x uses namespaces and it’s generally more C+±like. I am starting a project that will use Juce and OpenCV together, so I’ll be back here to post my own troubles and triumphs.

Matt


#8

Hi All,
I have returned! I’ve just gotten a little OpenCV+OpenGL demo working with Juce. I hope posting here will get out to someone.

Now I am using OpenCV 2.3 and the C++ style interface (cv::Mat, et cetera) and so I’m not having as much trouble with collisions as those above. Yet I still have to do this little hack to avoid the “T” collision, probably well-known around here:

[code]#ifdef _WIN32
#undef Rectangle
#undef T
#define Array tempArray

#include <windows.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>

#undef Array
#define T(x) L#x
#endif[/code]

My demo displays a rotating plane with the OpenCV camera capture applied as a texture. My OpenGL Component is based on the Juce OpenGL demo. Essentially: I merged the OpenGL demo with these OpenCV instructions. I set my MainWindow’s ContentComponent to my OpenGL Component:

Component* openGLWidget = createOpenGLWidget(); setContentComponent(openGLWidget);

It runs fine at 30 fps for maybe 1 minute before invariably throwing a memory access exception in the Juce Message Thread, somewhere in the process of ComponentPeer::handlePaint:

[code]void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
{
Graphics g (&contextToPaintTo);

#if JUCE_ENABLE_REPAINT_DEBUGGING
g.saveState();
#endif

JUCE_TRY
{
    component->paintEntireComponent (g, true);
}

JUCE_CATCH_EXCEPTION[/code]

What does it mean and what can I do?


#9

Hello
mmontag and ryanmcgee

I want to start learning with OpenCV, I know Juce well. Can you please give the combined openCV and Juce under one hat ?
It would be great if someone post it under useful tools.
Exactly what i want to know is how to convert iplImage(openCV) to Juce Image and viceversa ? Or how to display openCV images into Juce component ?

Thanks friends…


#10

Hi acn,
Check my blog post here, toward the end. http://www.mattmontag.com/development/notes-on-using-opencv-2-3-with-visual-studio-2010

Hope it helps!


#11

[quote=“mmontag”]Hi acn,
Check my blog post here, toward the end. http://www.mattmontag.com/development/notes-on-using-opencv-2-3-with-visual-studio-2010
[/quote]
Hey I checked it already… All the explanation is nice and really helping… Thanks for that.
But The link from which you borrowed code is not working now.
I see that you have cv::Mat to an OpenGL texture conversion, I would like to know how can cv:Mat can be converted to juceImage ?