Author Topic: OpenCV project wizard for MinGW and Linux  (Read 19923 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
OpenCV project wizard for MinGW and Linux
« on: April 30, 2013, 09:38:18 am »
Hi, I just create an OpenCV project wizard, I will put it here for some days until commit to trunk, comments are welcome.
Steps to use:
1,   unzip to share\CodeBlocks\templates\wizard\opencv
2,   add one line:
Code
    RegisterWizard(wizProject,     _T("opencv"),       _T("OpenCV project"),        _T("Console"));
in share\CodeBlocks\templates\wizard\config.script

Edit1: I'm using this release:
http://sourceforge.net/projects/opencvlibrary/files/opencv-win/, you can download either 2.4.3, 2.4.4 and 2.4.5 Windows installer

Edit2: You need to use MinGW 4.6.1dw2 if you want to link to the prebuild opencv libraries, see this for details: which mingw compiler is used to create the pre-build libs in 2.4.3 release - OpenCV Q&A Forum

Edit3: I did not tested this wizard on Linux, so it may have bugs. ;D







[attachment deleted by admin]
« Last Edit: April 30, 2013, 09:45:59 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: OpenCV project wizard for MinGW and Linux
« Reply #1 on: May 01, 2013, 03:17:28 pm »
I've finally tested it.

1- In the version number adjustment page, when an error occurs, the version number gets added to the file name again and again. I mean after I got a couple of path not found errors, I get an error message like "The lib path you entered seems invalid: File path\to\cv\lib/libopencv_core.244244244244244244244244.dll.a" not found. My CV version is '2.4.4.' btw. It seems to be searching for some file with lots of version repetitions in it which is not there actually. ;/

2- You included CV ver1 style headers in 'main.cpp', wouldn't it be better if they are ver2 style? Just a thought.

Couldn't go on testing it because of the error in step1, I'd like to continue after it's fixed though.

Win7 x64 SP1 cb rev8982

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: OpenCV project wizard for MinGW and Linux
« Reply #2 on: May 01, 2013, 03:25:45 pm »
I've finally tested it.

1- In the version number adjustment page, when an error occurs, the version number gets added to the file name again and again. I mean after I got a couple of path not found errors, I get an error message like "The lib path you entered seems invalid: File path\to\cv\lib/libopencv_core.244244244244244244244244.dll.a" not found. My CV version is '2.4.4.' btw. It seems to be searching for some file with lots of version repetitions in it which is not there actually. ;/
Thanks for report this, I will dig into it, I guess the wrong path was saved to configure file. I will add many log messages in the next version. :)

Quote
2- You included CV ver1 style headers in 'main.cpp', wouldn't it be better if they are ver2 style? Just a thought.
Ok, I will use more recent code cv::Mat.

Quote
Couldn't go on testing it because of the error in step1, I'd like to continue after it's fixed though.
Win7 x64 SP1 cb rev8982
Many thanks, I will fix the bugs you reported.

BTW: I have create a python script to debug opencv matrix when debugging. See:
Visualize in memory OpenCV image or matrix from GDB pretty printers
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: OpenCV project wizard for MinGW and Linux
« Reply #3 on: May 01, 2013, 04:25:57 pm »
Many thanks, I will fix the bugs you reported.

You're welcome and thanks to you for this wizard. ;)

I need to add, I had defined global variables for CV 'base', 'include' and 'lib' before I tested the wizard. Does the version adjustment change these variables or create new ones or...? I also didn't have a global variable for cv 'bin', what is that used for? Will it be better if I create it as a user-defined variable?

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: OpenCV project wizard for MinGW and Linux
« Reply #4 on: May 01, 2013, 04:52:19 pm »
I think I've found the bug.
Code
VersionString += Major;
VersionString += Minor;
VersionString += Revision;
Every time there is an error and the adjustment page cannot continue, these lines add 'Major' + 'Minor' + 'Revision' to 'VersionString' again and again.

I managed to get past the wizard by not making a mistake ever in the version adjustment and when I hit compile, it said,
Code
||=== Build: Debug in testcv (compiler: GNU GCC Compiler) ===|
ld.exe||cannot find -lopencv_imgproc244.dll|
ld.exe||cannot find -lopencv_core244.dll|
ld.exe||cannot find -lopencv_highgui244.dll|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Then I checked search directories and the entries were,
Code
$(#cv)\x86\mingw\lib
$(#cv)\x86\mingw\bin
but they should be,
Code
$(#cv.lib)
$(#cv.bin)
because I've changed them in version adjustment page to use these values. And if I change them manually, the wizard works.

Edit: I think the lines under 'function SetupProject(project)'
Code
project.AddIncludeDir(OpenCVPathDefaultInc);
project.AddLibDir(OpenCVPathDefaultLib);
project.AddLibDir(OpenCVPathDefaultBin);
should be
Code
project.AddIncludeDir(OpenCVPathInc);
project.AddLibDir(OpenCVPathLib);
project.AddLibDir(OpenCVPathBin);
« Last Edit: May 01, 2013, 05:04:45 pm by scarphin »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: OpenCV project wizard for MinGW and Linux
« Reply #5 on: May 02, 2013, 03:45:04 am »
I think I've found the bug.
Code
VersionString += Major;
VersionString += Minor;
VersionString += Revision;
Every time there is an error and the adjustment page cannot continue, these lines add 'Major' + 'Minor' + 'Revision' to 'VersionString' again and again.
Thanks, I fixed this bug by adding a line to reset the VersionString
Code
VersionString = _T(""); // set to empty string, then append three version numbers


Quote
...
Then I checked search directories and the entries were,
Code
$(#cv)\x86\mingw\lib
$(#cv)\x86\mingw\bin
but they should be,
Code
$(#cv.lib)
$(#cv.bin)
because I've changed them in version adjustment page to use these values. And if I change them manually, the wizard works.
1.
Code
$(#cv.bin)
does not exist. If you define a global variable named "cv", cv.include and cv.bin are automatically defined by C::B, but no "cv.bin". (see the code snippet in C::B source below). So if you leave cv.include setting empty in Global variable editor dialog, this value is translated to "include" subfolder of cv base.
Code
wxString UserVariableManager::Replace(const wxString& variable)
{
    wxString package = variable.AfterLast(wxT('#')).BeforeFirst(wxT('.')).MakeLower();
    wxString member  = variable.AfterFirst(wxT('.')).MakeLower();

    wxString path(cSets + m_ActiveSet + _T('/') + package + _T('/'));

    wxString base = m_CfgMan->Read(path + cBase);

    if (base.IsEmpty())
    {
        if (Manager::Get()->GetProjectManager()->IsLoading())
        {
            // a project/workspace is being loaded.
            // no need to bug the user now about global vars.
            // just preempt it; ProjectManager will call Arrogate() when it's done.
            Preempt(variable);
            return variable;
        }
        else
        {
            wxString msg;
            msg.Printf(_("In the currently active Set, Code::Blocks does not know\nthe global compiler variable \"%s\".\n\nPlease define it."), package.c_str());
            InfoWindow::Display(_("Global Compiler Variables"), msg , 8000, 1000);
            UsrGlblMgrEditDialog d;
            d.AddVar(package);
            PlaceWindow(&d);
            d.ShowModal();
        }
    }

    if (member.IsEmpty() || member.IsSameAs(cBase))
        return base;

    if (member.IsSameAs(cInclude) || member.IsSameAs(cLib) || member.IsSameAs(cObj))
    {
        wxString ret = m_CfgMan->Read(path + member);
        if (ret.IsEmpty())
            ret = base + _T('/') + member;
        return ret;
    }

    wxString ret = m_CfgMan->Read(path + member);
    return ret;
}

Notice: if (member.IsSameAs(cInclude) || member.IsSameAs(cLib) || member.IsSameAs(cObj))

The reason I use such setting is that when I extract the file: OpenCV-2.4.4.exe, I see such structure:
E:\code\opencv\OpenCV-2.4.4\opencv\build   -> I set this folder as "cv" base
E:\code\opencv\OpenCV-2.4.4\opencv\build\include  -> this becomes $(#cv.include), in-fact, it is the same as $(cv)\include, but we prefer the former way :).
E:\code\opencv\OpenCV-2.4.4\opencv\build\x86\mingw\lib -> this becomes $(#cv)\x86\mingw\lib
E:\code\opencv\OpenCV-2.4.4\opencv\build\x86\mingw\bin -> this becomes $(#cv)\x86\mingw\bin
The most import thing is the "cv" base, then all the sub-paths are relative paths.

2, In such directory structure, you can either set cv.lib in Global variable editor dialog as $(#cv)\x86\mingw\lib, then you can use $(#cv.lib) in your compiler settings, or you can leave cv.lib in Global variable editor dialog as empty string, then use $(#cv)\x86\mingw\lib in your compiler settings.

3, The reason I have $(#cv)\x86\mingw\bin in linker search paths is that C::B will automatically add this path to PATH when it run the app, so you don't need to add to bin paths to your system's PATH.

Quote
Edit: I think the lines under 'function SetupProject(project)'
Code
project.AddIncludeDir(OpenCVPathDefaultInc);
project.AddLibDir(OpenCVPathDefaultLib);
project.AddLibDir(OpenCVPathDefaultBin);
should be
Code
project.AddIncludeDir(OpenCVPathInc);
project.AddLibDir(OpenCVPathLib);
project.AddLibDir(OpenCVPathBin);
Thanks, fixed.

Quote
2- You included CV ver1 style headers in 'main.cpp', wouldn't it be better if they are ver2 style? Just a thought.
Ok, updated to new cv::Mat.

The attachment is the new wizard package, feedback are welcome, thanks.



[attachment deleted by admin]
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: OpenCV project wizard for MinGW and Linux
« Reply #6 on: May 02, 2013, 10:32:55 am »
Quote
...
Then I checked search directories and the entries were,
Code
$(#cv)\x86\mingw\lib
$(#cv)\x86\mingw\bin
but they should be,
Code
$(#cv.lib)
$(#cv.bin)
because I've changed them in version adjustment page to use these values. And if I change them manually, the wizard works.
1.
Code
$(#cv.bin)
does not exist. If you define a global variable named "cv", cv.include and cv.bin are automatically defined by C::B, but no "cv.bin". (see the code snippet in C::B source below). So if you leave cv.include setting empty in Global variable editor dialog, this value is translated to "include" subfolder of cv base.
When I said 'they should be, $(#cv.lib) and $(#cv.bin)', I meant my system, not general. Sorry for the confusion.

I made a user-defined 'bin' entry in global settings to point to the cv's bin directory which is '\cvfolder\bin' in my self build and NOT '\cvfolder\x86\mingw\bin'. But the wizard still use
Code
project.AddLibDir(OpenCVPathDefaultBin);
So this will always add '\cvfolder\x86\mingw\bin' to the project and not the one user defines on the settings page, '\cvfolder\bin' in my case. Was that on purpose?

One last thing, isn't it better to define '$(#cv.lib)' as the default value for 'OpenCVPathDefaultLib', in case there is a global variable setting already?

Wizard works ok now, thnx again. ;)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: OpenCV project wizard for MinGW and Linux
« Reply #7 on: May 02, 2013, 11:48:22 am »
I made a user-defined 'bin' entry in global settings to point to the cv's bin directory which is '\cvfolder\bin' in my self build and NOT '\cvfolder\x86\mingw\bin'. But the wizard still use
Code
project.AddLibDir(OpenCVPathDefaultBin);
So this will always add '\cvfolder\x86\mingw\bin' to the project and not the one user defines on the settings page, '\cvfolder\bin' in my case. Was that on purpose?

One last thing, isn't it better to define '$(#cv.lib)' as the default value for 'OpenCVPathDefaultLib', in case there is a global variable setting already?
Well, this is indeed a mistake, sorry, I changed to "OpenCVPathLib".

BTW:
I changed my file/folder structure, now the folders are: (I also change all the default paths to follow the below structure)
E:\code\opencv\OpenCV-2.4.4\opencv\build   -> I set this folder as "cv" base
E:\code\opencv\OpenCV-2.4.4\opencv\build\include  ->  include path
E:\code\opencv\OpenCV-2.4.4\opencv\build\lib -> lib path
E:\code\opencv\OpenCV-2.4.4\opencv\build\bin -> bin path

Now, I follow your advice, and add a sub-field named "bin" and set its value to "$(#cv)\bin", then everything works fine.

I think if I add a sub-field named "bin", but left its value as empty string, C::B should default set it to "$(#cv)\bin", just the similar way as "lib" and "include", but this is just a feature request in C::B. :)

Attachment is the version 2 of the wizard, thanks for your feedbacks.



[attachment deleted by admin]
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: OpenCV project wizard for MinGW and Linux
« Reply #8 on: May 02, 2013, 03:33:45 pm »
I think if I add a sub-field named "bin", but left its value as empty string, C::B should default set it to "$(#cv)\bin", just the similar way as "lib" and "include", but this is just a feature request in C::B. :)
I think it is quite easy to implement this feature request, look at the last lines of function: UserVariableManager::Replace
Code
wxString UserVariableManager::Replace(const wxString& variable)
{
    wxString package = variable.AfterLast(wxT('#')).BeforeFirst(wxT('.')).MakeLower();
    wxString member  = variable.AfterFirst(wxT('.')).MakeLower();
    ...
    ...
    if (member.IsEmpty() || member.IsSameAs(cBase))
        return base;

    if (member.IsSameAs(cInclude) || member.IsSameAs(cLib) || member.IsSameAs(cObj))
    {
        wxString ret = m_CfgMan->Read(path + member);
        if (ret.IsEmpty())
            ret = base + _T('/') + member;
        return ret;
    }

    wxString ret = m_CfgMan->Read(path + member);
    return ret;
}

The last two line:
Code
    wxString ret = m_CfgMan->Read(path + member);
    return ret;
Can change to:
Code
    
    wxString ret = m_CfgMan->Read(path + member);
    if (ret.IsEmpty())
        ret = base + _T('/') + member;
    return ret;
So, if member-field "bin" has defined but have an empty value string, we use the sub-folder of "bin", any ideas?

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: OpenCV project wizard for MinGW and Linux
« Reply #9 on: May 02, 2013, 03:38:48 pm »
So, if member-field "bin" has defined but have an empty value string, we use the sub-folder of "bin", any ideas?
Well but what if you toggle a compiler flag and want to have it on ("-Wall") in the one case and off ("") in the other case? This is not covered then as "" will be translated all the time which is not what you want.

As it is now, you can safely just enter "bin" (the fields name) into it and it will work as desired in all cases.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: OpenCV project wizard for MinGW and Linux
« Reply #10 on: May 02, 2013, 03:48:15 pm »
So, if member-field "bin" has defined but have an empty value string, we use the sub-folder of "bin", any ideas?
Well but what if you toggle a compiler flag and want to have it on ("-Wall") in the one case and off ("") in the other case? This is not covered then as "" will be translated all the time which is not what you want.

As it is now, you can safely just enter "bin" (the fields name) into it and it will work as desired in all cases.
I see. Maybe, we can add a special member named "bin" (like the include, lib, obj), I think it is quite common that a bin folder contains executable or dll files under Windows.  :)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: OpenCV project wizard for MinGW and Linux
« Reply #11 on: May 02, 2013, 04:02:54 pm »
I see. Maybe, we can add a special member named "bin" (like the include, lib, obj), I think it is quite common that a bin folder contains executable or dll files under Windows.  :)
Yes, I agree. I have indeed several GCV's where I put the "bin" folder into the custom fields.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: OpenCV project wizard for MinGW and Linux
« Reply #12 on: May 02, 2013, 04:51:41 pm »
This patch implement the pre-defined "bin" member field.

Code
Index: resources/global_uservars.xrc
===================================================================
--- resources/global_uservars.xrc (revision 9011)
+++ resources/global_uservars.xrc (working copy)
@@ -241,6 +241,32 @@
  <flag>wxBOTTOM|wxRIGHT|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
  <border>5</border>
  </object>
+ <object class="sizeritem">
+ <object class="wxStaticText" name="ID_STATICTEXT_BIN">
+ <label>bin</label>
+ <font>
+ <size>10</size>
+ <weight>bold</weight>
+ <family>swiss</family>
+ <face>Arial</face>
+ </font>
+ </object>
+ <flag>wxBOTTOM|wxLEFT|wxRIGHT|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+ <border>5</border>
+ </object>
+ <object class="sizeritem">
+ <object class="wxTextCtrl" name="bin" />
+ <flag>wxBOTTOM|wxRIGHT|wxEXPAND|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+ <border>5</border>
+ </object>
+ <object class="sizeritem">
+ <object class="wxButton" name="fs5">
+ <label>...</label>
+ <size>20,-1</size>
+ </object>
+ <flag>wxBOTTOM|wxRIGHT|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
+ <border>5</border>
+ </object>
  <object class="spacer">
  <flag>wxBOTTOM|wxLEFT|wxRIGHT|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
  <border>5</border>
Index: uservarmanager.cpp
===================================================================
--- uservarmanager.cpp (revision 9011)
+++ uservarmanager.cpp (working copy)
@@ -47,6 +47,7 @@
 const wxString cInclude  (_T("include"));
 const wxString cLib      (_T("lib"));
 const wxString cObj      (_T("obj"));
+const wxString cBin      (_T("bin"));
 const wxString cCflags   (_T("cflags"));
 const wxString cLflags   (_T("lflags"));
 const wxString cSets     (_T("/sets/"));
@@ -75,6 +76,7 @@
     wxTextCtrl *m_Include;
     wxTextCtrl *m_Lib;
     wxTextCtrl *m_Obj;
+    wxTextCtrl *m_Bin;
 
     wxTextCtrl *m_Name[7];
     wxTextCtrl *m_Value[7];
@@ -155,7 +157,7 @@
     if (member.IsEmpty() || member.IsSameAs(cBase))
         return base;
 
-    if (member.IsSameAs(cInclude) || member.IsSameAs(cLib) || member.IsSameAs(cObj))
+    if (member.IsSameAs(cInclude) || member.IsSameAs(cLib) || member.IsSameAs(cObj) || member.IsSameAs(cBin))
     {
         wxString ret = m_CfgMan->Read(path + member);
         if (ret.IsEmpty())
@@ -292,6 +294,7 @@
     m_Include = XRCCTRL(*this, "include", wxTextCtrl);
     m_Lib     = XRCCTRL(*this, "lib",     wxTextCtrl);
     m_Obj     = XRCCTRL(*this, "obj",     wxTextCtrl);
+    m_Bin     = XRCCTRL(*this, "bin",     wxTextCtrl);
 
     wxSplitterWindow *splitter = XRCCTRL(*this, "splitter", wxSplitterWindow);
     if (splitter)
@@ -629,6 +632,8 @@
         c = m_Lib;
     else if (id == XRCID("fs4"))
         c = m_Obj;
+    else if (id == XRCID("fs5"))
+        c = m_Bin;
     else
         cbThrow(_T("Encountered invalid button ID"));
 

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: OpenCV project wizard for MinGW and Linux
« Reply #13 on: May 08, 2013, 09:58:32 am »
I'm going to commit the patch above as there is not objections for one day or two. ;)
After that, I'm going to commit the project wizard for OpenCV.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: OpenCV project wizard for MinGW and Linux
« Reply #14 on: May 09, 2013, 04:31:51 am »
I'm going to commit the patch above as there is not objections for one day or two. ;)
After that, I'm going to commit the project wizard for OpenCV.
Done in rev 9063 and rev9064, thanks.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.