Author Topic: opencv 2.3 and codeBlocks on windows 7 64  (Read 42698 times)

kukolog

  • Guest
opencv 2.3 and codeBlocks on windows 7 64
« on: July 21, 2011, 12:00:32 pm »
Hello

I am trying to make the most basic example of open cv to compile, but looks like something is terrible wrong.

Info about what I am using:

OS: windows ultimate 7 64

Codeblocks 10:05 installed from "codeblocks-10.05mingw-setup.exe"
into d:\develop\codeblocks

opencv2.3 installed from "OpenCV-2.3.0-win-superpack.exe"
into d:\develop\OpenCV2.3

This is the code  I am trying to compile
Code
#include "cv.h"
#include "highgui.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>

const char* cascade_name = "D:\\develop\\OpenCV2.3\\opencv\\data\\haarcascades\\haarcascade_frontalface_alt.xml";
void detect_and_draw( IplImage* image );

int main( int argc, char** argv )
{
    IplImage *img = cvLoadImage("face.jpg");
    detect_and_draw(img);
    cvWaitKey();
    cvReleaseImage(&img);
    cvDestroyWindow("result");
    return 0;
}

void detect_and_draw( IplImage* img )
{
    static CvMemStorage* storage = 0;
    static CvHaarClassifierCascade* cascade = 0;
    int scale = 1;
    IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 );
    CvPoint pt1, pt2;
    int i;
    cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
    if( !cascade )
    {
        fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
        return;
    }

    storage = cvCreateMemStorage(0);
    cvNamedWindow( "result", 1 );

    cvClearMemStorage( storage );
    if( cascade )
    {
        CvSeq* faces = cvHaarDetectObjects( img, cascade, storage,1.1, 2, CV_HAAR_DO_CANNY_PRUNING,cvSize(40, 40) );
        for( i = 0; i < (faces ? faces->total : 0); i++ )
        {
            CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
            pt1.x = r->x*scale;
            pt2.x = (r->x+r->width)*scale;
            pt1.y = r->y*scale;
            pt2.y = (r->y+r->height)*scale;
            cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
        }
    }
    cvShowImage( "result", img );
    cvReleaseImage( &temp );
}

What I added into my C::B config :

into the Project Build options -> Linker settings tab , I added all Libs from D:\develop\OpenCV2.3\build\x86\mingw\lib\*.dll.a
( I tried with ...\x64\... also )

nto the Project Build options -> Search Directories , I added:
D:\develop\OpenCV2.3\build\include
D:\develop\OpenCV2.3\build\include\opencv
D:\develop\OpenCV2.3\build\include\opencv2

This cause :
Code
-------------- Build: Release in opencv ---------------

Compiling: main.cpp
Linking console executable: bin\Release\opencv.exe
obj\Release\main.o:main.cpp:(.text+0x2d): undefined reference to `cvCreateImage'
obj\Release\main.o:main.cpp:(.text+0x55): undefined reference to `cvLoad'
obj\Release\main.o:main.cpp:(.text+0x6e): undefined reference to `cvCreateMemStorage'
obj\Release\main.o:main.cpp:(.text+0x87): undefined reference to `cvNamedWindow'
obj\Release\main.o:main.cpp:(.text+0x94): undefined reference to `cvClearMemStorage'
obj\Release\main.o:main.cpp:(.text+0xfa): undefined reference to `cvHaarDetectObjects'
obj\Release\main.o:main.cpp:(.text+0x12f): undefined reference to `cvGetSeqElem'
obj\Release\main.o:main.cpp:(.text+0x1c4): undefined reference to `cvRectangle'
obj\Release\main.o:main.cpp:(.text+0x1e7): undefined reference to `cvShowImage'
obj\Release\main.o:main.cpp:(.text+0x1f2): undefined reference to `cvReleaseImage'
obj\Release\main.o:main.cpp:(.text+0x256): undefined reference to `cvLoadImage'
obj\Release\main.o:main.cpp:(.text+0x26e): undefined reference to `cvWaitKey'
obj\Release\main.o:main.cpp:(.text+0x27a): undefined reference to `cvReleaseImage'
obj\Release\main.o:main.cpp:(.text+0x286): undefined reference to `cvDestroyWindow'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)

Then
I added into the linker options  -lhighgui  to see what happens and I got a "cannot find -lhighthui"
I added into the linker options -lopencv_highgui "cannot find -lopencv_hightgui"

I really need some help here.

I know how to use google.
I know how to use search here , there are just a few topics on opencv here I and read all of them.

this:
http://opensourcecollection.blogspot.com/2011/04/how-to-setup-opencv-22-in-codeblocks.html  <- dont help
http://opencv.willowgarage.com/wiki/CodeBlocks <- don't help.

But
It worked with this configuration with a windowsXP Sp3, C::B 10.05 without mingw ( installed from mingw installer into c:\minGW ) and opencv 2.2
But I need that working on the w7 box

I am accepting suggestions. Lots of them. I am trying this for more than 2 weeks.

Thanks

Luis

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #1 on: July 21, 2011, 12:47:22 pm »
Read this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_I_would_like_to_compile_a_project_using_some_non-standard_libraries._How_can_I_indicate_to_CodeBlocks_that_these_libraries_and_include_files_exist.3F
And this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

Specifying libraries is a two step process:
1. specify the path to the lib
2. specify the name of the lib (no prefix and no extension)

If you combine 1 and 2 in one step it won't work...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline paflechien

  • Single posting newcomer
  • *
  • Posts: 2
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #2 on: July 21, 2011, 10:10:57 pm »
hi,

i'm new to code::blocks, and i think i've found a great (and free!) alternative to the combo visual C++/visual assist. so far, it's a pleasure to use it.
anyway, i've been trying to compile a simple program using opencv 2.3 under windows 7 32bits, and i've installed code::blocks from "codeblocks-10.05mingw-setup.exe" in program files dir, and opencv from "OpenCV-2.3.0-win-superpack.exe" in d:\dev\. everything is set up like kukolog did. here is the code:
Code
#include <iostream>
#include "opencv/cv.h"
#include "opencv/highgui.h"

using namespace std;

int main()
{
    cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
    return 0;
}
it's fairly minimal, just to be sure the project setup is ok. actually, i'm getting the following error :
undefined reference to `cvNamedWindow'

i've tried a lot of things concerning opencv previous versions, including setting libs in project build options, global settings, relative path, absolute path, and so on. nothing worked.
i think the issue might be due to the lib format (.dll.a), different from previous versions (.lib).

if anyone has a clue about a solution, you're greatly welcome :)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #3 on: July 22, 2011, 12:20:00 am »
As stated many times, MinGW doesn't support .lib files, it expects .a files (ar archives) and newer versions (I think) support .dll-s directly.
So the only thing you need to do is put the dlls in the search path for libraries...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #4 on: July 22, 2011, 03:26:41 am »
Mostly, you need a OpenCV 2.3 library for MinGW (Not the library for Visual C++)
If it does not exist, then you should build from OpenCV source your self. (using Cmake+mingw)
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 paflechien

  • Single posting newcomer
  • *
  • Posts: 2
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #5 on: July 22, 2011, 07:41:30 am »
hi guys, thanks for the replies :)

actually, the opencv 2.3 mega pack comes with pre compiled libs for mingw, vc9 and vc10.
however, the mingw doesn't seem to be good, as i've been finally able to successfully compile a project after building opencv 2.3 with mingw (steps are described here for the 2.2, and works for 2.3).
then, as obfuscated said, just add in the linker search path the path to the .dll (the path to the .dll.a is not required)
enjoy :)

thanks all !

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #6 on: July 22, 2011, 08:52:15 pm »
As stated many times, MinGW doesn't support .lib files
Sorry to say this, but this is not true. In fact, MinGW handles .lib files just fine in 99% of the cases. Take e.g. the Direct/X SDK (the one directly downloaded from MS) - this works just fine.
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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #7 on: July 22, 2011, 11:43:14 pm »
Morten, are you sure you're using the libs not the dll's?
Last time I've played with MinGW, I've to search very hard how to convert the opengl libs to .a files...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #8 on: July 23, 2011, 10:08:18 pm »
Morten, are you sure you're using the libs not the dll's?
Certainly - as the DLL's are in a different folder, not known by the linker. Using process monitor (sysinternals) reveals the link goes against the *.lib files.
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 harold44

  • Single posting newcomer
  • *
  • Posts: 3
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #9 on: July 26, 2011, 11:56:43 am »
Hello

I am trying too to make like you but  i have a message :
"Opencv - Debug" uses an invalid compiler [YOUR ANSWER IS ALREADY THERE. SEARCH THE FORUMS!]. Probably the toolchain path within the compiler options is not setup correctly?! Skipping...
"Opencv - Debug" uses an invalid compiler [YOUR ANSWER IS ALREADY THERE. SEARCH THE FORUMS!]. Probably the toolchain path within the compiler options is not setup correctly?! Skipping...
Nothing to be done.
What is that somebody has a simple solution so that work.
Thank for advance

Harold

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #10 on: July 26, 2011, 07:12:17 pm »
@harold44:

Install a supported compiler.
Configure the Code::Blocks compiler settings (toolchain) to use the compiler you installed.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline harold44

  • Single posting newcomer
  • *
  • Posts: 3
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #11 on: July 26, 2011, 09:57:47 pm »
thank you, but now I try to install opencv 2.3 but without success.

Offline harold44

  • Single posting newcomer
  • *
  • Posts: 3
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #12 on: July 27, 2011, 05:09:10 pm »
Hello,
Which is the procedure to be able to use OpenCV 2.3 sous codeblocks10.05 under vista or under Windows 7.
I look for 10 days but unsuccessfully.
Thank you in advance

12oclocker

  • Guest
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #13 on: October 19, 2011, 01:23:34 am »
OpenCV 2.3.1 has no documentation on how to correctly install with codeblocks.
I have ZERO problems with other stuff. OpenCV configuration = NIGHTMARE.
Once I link to OpenCV 2.3.1 libraries, and compile, I get stupid errors like "libstdc++-6.dll is missing",
I find NO WAY to fix this, and NO DATA on how to correctly configure with codeblock's DEFAULT compiler.
I hate VS compiler, and refuse to use it after discovering it would inject garbage and bugs into good code, I would rather use the default in codeblocks.
If someone has a step by step on how to setup with codeblocks, using the default GCC compiler settings for win7, please tell.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: opencv 2.3 and codeBlocks on windows 7 64
« Reply #14 on: October 19, 2011, 01:43:30 am »
The third party library section on the Code::Blocks wiki has the following link: Using OpenCV with Code::Blocks.

Note: I have never used OpenCV, so I cannot guaranty the page's accuracy.