`
ihuashao
  • 浏览: 4665049 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

OPENCV 在MINGW 环境下的编译

阅读更多
因为某种原因,需要在MINGW下编译OPENCV,本以为是一个比较简单的事情,孰知竟然也陆陆续续花了不少的精力,即使到现在这个地步,也还有部分不甚满意的地方。综合看,OPENCV的的正常运行需要很多库的支持。在MS的VC++和正常的LINUX发布版本下,这些支持都是默认的,而在MINGW 下,却需要一一提供,因此也颇费一番周折,先把过程列举如下,希望能够今后做同样事情的人有所裨益。

第1步:下载 MINGW 和 MSYS

* 下载的版本是:MSYS-1.0.10.exemsysDTK-1.0.1.exe 和 MinGW-5.1.4.exe。
* 按照下载软件的基本提示,分别安装到 c:\mingw 和 c:\msys\1.0运行
* 问题:直接运行 msys.bat 出现问题,控制台窗口无法启动。所有的命令都出现 " Couldn't reserve space for cygwin's heap"
上网查找问题,解决方法是用 rebase 进行处理。 具体方法是:
- 启动CMD命令行程序,在DOS窗口下,依次运行:
cd c:\msys\1.0\bin
rebase -b 0x30000000 msys-1.0.dll
* 编辑 /etc/fstab,写入下面的映射关系:
c:/mingw /mingw
c:/mingw /usr/local
* 编辑 /etc/profile,在文件末尾增加下面几行:
#进入的缺省目录是根目录
cd "/"
#列举目录时有颜色信息
alias ls='ls --color'
alias dir='ls --color'

第2步:下载 OPENCV V1.0 FOR LINUX

* 下载OPENCV1.0 for linux 解压到/home/opencv(就是 c:\msys\1.0\home目录下)
* 从第3步开始到开始配置OPENCV,均是做一些准备工作以及配置必要的支持库。

第3步:下载pkg-config

下载地址为:http://rt.openfoundry.org/Foundry/Project/Download/。将二进制的解压包解压拷贝到 c:\mingw目录下;

第4步:安装 GTK,保证对图像I/O的支持

* 下载下面的文件,解压后释放到 C:\MinGW 目录下
* pkg-config-0.23.zip
* libiconv-1.9.1.bin.woe32.zip
* gettext-0.14.5.zip
* gettext-dev-0.14.5.zip
* pango-1.16.4.zip
* pango-dev-1.16.4.zip
* cairo-1.4.14.zip
* cairo-dev-1.4.0.zip
* zlib-1.2.3.zip
* libpng-1.2.8.zip
* libpng-dev-1.2.8.zip
* atk-1.20.0.zip
* atk-dev-1.20.0.zip
* gtk+-2.12.8.zip
* gtk+-dev-2.12.8.zip
* libintl-0.14.4-lib.zip

第5步:安装编译FFMPEG

* 下载地址是:http://download.chinaunix.net。将下载的ffmpeg-0.4.9- p20060302.tar.bz2 解压到/home/ffmpeg 下,
* 编译
./configure --enable-memalign-hack
make
make test
make install
* 注意这个包直接安装到 c:/program files/ffmpeg 中,需要把该目录下的 ./lib 和 ./include 目录移动到 c:/mingw (也就是 /usr/local)下, ffmpeg.exe 移到 c:/mingw/bin 下。

第6步:编译JPEG/JASPER/TIFF 等图像库

* 下载 jpegsrc.v6b.tar.gz,jasper-1.900.1.zip,tiff-3.8.2-3-src.tar.bz2
* 依次安装说明编译、测试、安装。

第7步:拷贝GTK所需要的运行库

iconv.dll
intl.dll
libatk-1.0-0.dll
libgdk-win32-2.0-0.dll
libgdk_pixbuf-2.0-0.dll
libgtk-win32-2.0-0.dll
libiconv2.dll
libpango-1.0-0.dll
libpangowin32-1.0-0.dll

第8步:编译 OPENCV

* 运行配置文件:
./configure --without-carbon --without-quicktime --without-1394libs --without-python

--without-swig --enable-static --disable-shared --disable-apps
* 配置参数定义是
--without-gtk:忽略gtk+2.0 windows
--without-carbon: 不使用Mac OS上的X库
--without-quicktime
--without-1394libs
--without-python
--without-swig
--enable-static :生成静态库
--disable-shared:不生成动态库
* 配置的运行结果如下

$ ./configure --without-carbon --without-quicktime --without-1394libs --witho
ut-python --without-swig --enable-static --disable-shared --disable-apps
checking build system type... i686-pc-mingw32
checking host system type... i686-pc-mingw32
checking target system type... i686-pc-mingw32
checking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make sets $(MAKE)... (cached) yes
checking for g++... g++
checking for C++ compiler default output file name... a.exe
checking whether the C++ compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... .exe
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for a sed that does not truncate output... /bin/sed
checking for egrep... grep -E
checking for ld used by gcc... c:/mingw/mingw32/bin/ld.exe
checking if the linker (c:/mingw/mingw32/bin/ld.exe) is GNU ld... yes
checking for c:/mingw/mingw32/bin/ld.exe option to reload object files... -r
checking for BSD-compatible nm... /usr/local/bin/nm
checking whether ln -s works... yes
checking how to recognise dependent libraries... file_magic file format pei*-i3
6(.*architecture: i386)?
checking for dlltool... dlltool
checking for as... as
checking for objdump... objdump
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... no
checking dlfcn.h presence... no
checking for dlfcn.h... no
checking how to run the C++ preprocessor... g++ -E
checking for g77... no
checking for f77... no
checking for xlf... no
checking for frt... no
checking for pgf77... no
checking for fort77... no
checking for fl32... no
checking for af77... no
checking for f90... no
checking for xlf90... no
checking for pgf90... no
checking for epcf90... no
checking for f95... no
checking for fort... no
checking for xlf95... no
checking for ifc... no
checking for efc... no
checking for pgf95... no
checking for lf95... no
checking for gfortran... no
checking whether we are using the GNU Fortran 77 compiler... no
checking whether accepts -g... no
checking the maximum length of command line arguments... 8192
checking command to parse /usr/local/bin/nm output from gcc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -DDLL_EXPORT
checking if gcc PIC flag -DDLL_EXPORT works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking whether the gcc linker (c:/mingw/mingw32/bin/ld.exe) supports shared l
braries... yes
checking dynamic linker characteristics... Win32 ld.exe
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... no
checking whether to build static libraries... yes
configure: creating libtool
appending configuration tag "CXX" to libtool
checking for ld used by g++... c:/mingw/mingw32/bin/ld.exe
checking if the linker (c:/mingw/mingw32/bin/ld.exe) is GNU ld... yes
checking whether the g++ linker (c:/mingw/mingw32/bin/ld.exe) supports shared l
braries... yes
checking for g++ option to produce PIC... -DDLL_EXPORT
checking if g++ PIC flag -DDLL_EXPORT works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (c:/mingw/mingw32/bin/ld.exe) supports shared l
braries... yes
checking dynamic linker characteristics... Win32 ld.exe
checking how to hardcode library paths into programs... immediate
appending configuration tag "F77" to libtool
checking whether to build debug version (no optimization)... no
configure: TARGET=i686-pc-mingw32
checking for pow in -lm... yes
checking for dlopen in -ldl... no
checking for pthread_create in -lpthread... no
checking whether byte ordering is bigendian... no
checking for working alloca.h... no
checking for alloca... yes
checking malloc.h usability... yes
checking malloc.h presence... yes
checking for malloc.h... yes
checking for lrint... yes
checking for pkg-config... /usr/local/bin/pkg-config
checking for "gtk+-2.0 gdk-pixbuf-2.0"... yes
checking GTK_CFLAGS... -mms-bitfields -Ic:/mingw/include/gtk-2.0 -Ic:/mingw/lib
gtk-2.0/include -Ic:/mingw/include/atk-1.0 -Ic:/mingw/include/cairo -Ic:/mingw/
nclude/pango-1.0 -Ic:/mingw/include/glib-2.0 -Ic:/mingw/lib/glib-2.0/include
checking GTK_LIBS... -Lc:/mingw/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -
pangowin32-1.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lgobject-
.0 -lgmodule-2.0 -lglib-2.0 -lintl
checking for "gthread-2.0"... yes
checking GTHREAD_CFLAGS... -Ic:/mingw/include/glib-2.0 -Ic:/mingw/lib/glib-2.0/
nclude
checking GTHREAD_LIBS... -Lc:/mingw/lib -lgthread-2.0 -lglib-2.0 -lintl
checking ffmpeg/avcodec.h usability... yes
checking ffmpeg/avcodec.h presence... yes
checking for ffmpeg/avcodec.h... yes
checking for avcodec_decode_video in -lavcodec... no
checking linux/videodev.h usability... no
checking linux/videodev.h presence... no
checking for linux/videodev.h... no
checking for linux/videodev2.h... no
checking jpeglib.h usability... yes
checking jpeglib.h presence... yes
checking for jpeglib.h... yes
checking for jpeg_destroy_decompress in -ljpeg... yes
checking zlib.h usability... yes
checking zlib.h presence... yes
checking for zlib.h... yes
checking for gzopen in -lz... yes
checking png.h usability... yes
checking png.h presence... yes
checking for png.h... yes
checking libpng/png.h usability... no
checking libpng/png.h presence... no
checking for libpng/png.h... no
checking for png_read_image in -lpng12... yes
checking for png_get_valid... yes
checking for png_set_tRNS_to_alpha... yes
checking tiff.h usability... yes
checking tiff.h presence... yes
checking for tiff.h... yes
checking for TIFFReadRGBAStrip in -ltiff... yes
checking jasper/jasper.h usability... yes
checking jasper/jasper.h presence... yes
checking for jasper/jasper.h... yes
checking for jas_image_readcmpt in -ljasper... yes
checking ImfCRgbaFile.h usability... no
checking ImfCRgbaFile.h presence... no
checking for ImfCRgbaFile.h... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating opencv.pc
config.status: creating opencv.spec
config.status: creating docs/Makefile
config.status: creating data/Makefile
config.status: creating cxcore/Makefile
config.status: creating cxcore/include/Makefile
config.status: creating cxcore/src/Makefile
config.status: creating cv/Makefile
config.status: creating cv/include/Makefile
config.status: creating cv/src/Makefile
config.status: creating cvaux/Makefile
config.status: creating cvaux/include/Makefile
config.status: creating cvaux/src/Makefile
config.status: creating ml/Makefile
config.status: creating ml/include/Makefile
config.status: creating ml/src/Makefile
config.status: creating otherlibs/Makefile
config.status: creating otherlibs/highgui/Makefile
config.status: creating apps/Makefile
config.status: creating apps/haartraining/Makefile
config.status: creating apps/haartraining/include/Makefile
config.status: creating apps/haartraining/src/Makefile
config.status: creating interfaces/Makefile
config.status: creating interfaces/swig/Makefile
config.status: creating interfaces/swig/filtered/Makefile
config.status: creating interfaces/swig/general/Makefile
config.status: creating interfaces/swig/python/Makefile
config.status: creating tests/Makefile
config.status: creating tests/python/Makefile
config.status: creating tests/cv/Makefile
config.status: creating tests/cv/src/Makefile
config.status: creating tests/cxts/Makefile
config.status: creating tests/cxcore/Makefile
config.status: creating tests/cxcore/src/Makefile
config.status: creating utils/Makefile
config.status: creating samples/Makefile
config.status: creating samples/c/Makefile
config.status: creating samples/python/Makefile
config.status: creating cvconfig.h
config.status: cvconfig.h is unchanged
config.status: executing depfiles commands

General configuration ================================================
Compiler: g++
CXXFLAGS: -Wall -fno-rtti -pipe -O3 -g -march=i686 -ffast-m
th -fomit-frame-pointer

Install path: /usr/local

HighGUI configuration ================================================

Windowing system --------------
Use Carbon / Mac OS X: no
Use gtk+ 2.x: yes
Use gthread: yes

Image I/O ---------------------
Use libjpeg: yes
Use zlib: yes
Use libpng: yes
Use libtiff: yes
Use libjasper: yes
Use libIlmImf: no

Video I/O ---------------------
Use QuickTime / Mac OS X: no
Use xine: no
Use ffmpeg: no
Use dc1394 & raw1394: no
Use v4l: no
Use v4l2: no

Wrappers for other languages =========================================
SWIG
Python no

Additional build settings ============================================
Build demo apps no

Now run make ...

* 编译:
make
* 安装:
make install
* 检查:可以看到能够生产 cxcore 和 cv 的测试文件,并且测试通过。
make check
* 安装
make install
将库和头文件分别安装到 /usr/local/lib 和 /usr/local/include/opencv 下

第9步:测试

* 不需要图像I/O操作的,可以自己用下列方式编译:
g++ -o sample.exe sample.c -I/usr/local/include/opencv -L/usr/local/lib -lcv -lcvaux
-lcxcore -lml -lhighgui
* 需要图像I/O操作的,用下面方式编译:
g++ -o sample.exe sample.c -I/usr/local/include/opencv
-L/usr/local/lib -lhighgui -lcv -lcxcore -lcvaux -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0
-lpangowin32-1.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -ljpeg -lpng -ltiff -ljasper -lgthread-2.0

第10步:需要解决的几个问题

* HIGHGUI/window_gtk.cpp 不编译的问题;解决办法是重新改写 window_gtk.cpp 程序,将
#ifdef HAVE_GTK
...
#endif
有关定义GTK的预编译指令注释掉
* 解决图像I/O问题:如果图像的I/O函数无法使用,在编译时候总是出现如下错误:
c:/mingw/lib/libhighgui.a(loadsave.o): In function `Z41__static_initialization_a
nd_destruction_0ii':
c:/msys/1.0/home/opencv/otherlibs/highgui/loadsave.cpp:337: undefined reference
to `cvShowImage'
collect2: ld returned 1 exit status
* 修改 /usr/local/include/jmorecfg.h 中定义 boolean 的地方,解决 boolean 的定义冲突,注释掉 boolean 的定义
#ifndef HAVE_BOOLEAN
//typedef int boolean;
#endif


第11步:遗留的几个问题

(1)JPEG文件的读取有问题,就是说 cvLoadImage 不能正确读取 jpeg 文件;
(2)cvSaveImage 有问题,无法存图片;
(3)FFMPEG无法使用,故视频不能做处理;

第12步:编译SAMPLES/C下的样例程序

编辑 makefile.gnu
LINKFLAGS = -L"/usr/local/lib" -lhighgui -lcv -lcxcore -lcvaux -lgtk-win32-2.0

-lgdk-win32-2.0 -latk-1.0 -lpangowin32-1.0 -lpangocairo-1.0 -lpango-1.0 -lcairo

-lgdk_pixbuf-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -ljpeg -lpng -ltiff -ljasper

-lgthread-2.0

替换原有的 LINKFLAGS 变量

输入指令:
make -f makefile.gnu
编译,然后运行
分享到:
评论

相关推荐

    opencv的MinGW 64位编译版本

    由于你使用的是64位MinGW编译版本,这些库名通常是以"opencv_"开头,例如"opencv_core"、"opencv_highgui"等。根据你的应用需求,添加相应的库。注意,库名在Qt中需要写成"libopencv_core"、"libopencv_highgui"的...

    OpenCV4.5.3 MinGW X64编译

    在本场景中,我们讨论的是如何使用MinGW X64编译器对OpenCV 4.5.3进行编译,以创建一个可以直接在Qt环境中使用的开发包。 首先,MinGW(Minimalist GNU for Windows)是一个GNU工具集,包含了C、C++等编译器,用于...

    OpenCV3.4.2 MinGW32编译

    通过以上步骤,你应该能够在MinGW32环境下成功编译和运行包含OpenCV的项目。理解这些知识点是成为熟练使用OpenCV的开发者的第一步。在实践中不断探索和学习,你将能够利用OpenCV的强大功能解决各种计算机视觉问题。

    opencv3.4.3 mingw32编译

    文件"opencv343_mingw32"可能是编译后的库文件、头文件和示例程序的打包,供用户直接在32位Windows环境下使用。使用这些文件,开发者无需自己编译,可以直接将它们链接到他们的项目中,大大简化了开发流程。 总的来...

    opencv3.0.0 mingw x86 windows 10编译好的包

    在本案例中,我们讨论的是OpenCV 3.0.0版本,专为MingW 32位环境和Windows 10操作系统编译优化的版本。 1. **OpenCV 3.0.0**:这是OpenCV的一个重要版本,引入了许多新功能和改进。例如,它加强了深度学习的支持,...

    opencv-3.4.5-mingw-32位(window下用MINGW编译32位的opencv)

    在Windows环境下,使用mingw编译32位OpenCV时,通常会遇到兼容性问题、库依赖和编译选项设置等问题。这个预编译版本解决了这些问题,使得开发者可以专注于自己的应用开发,而不是底层库的配置。为了在项目中使用这个...

    OpenCV 2.4.9 mingw编译库文件

    总的来说,OpenCV 2.4.9 MingW编译库文件为开发者提供了一个在Qt 5.6.0 MingW环境下使用OpenCV的基础,简化了编译和链接过程,使得开发者能够更加专注于他们的图像处理和计算机视觉应用的开发。正确配置和使用这些库...

    opencv3.2 MinGW编译版本

    总结来说,本项目提供了一个使用CMake和MinGW编译的OpenCV 3.2 32位版本,这对于那些在Windows平台上使用MinGW的开发者来说是一个宝贵的资源,他们可以直接使用这个编译好的版本,而无需自行编译庞大的OpenCV源代码...

    Qt5.15.2+openCV4.5.5+mingw32编译生成的动态库(不带world)

    Qt5.15.2+openCV4.5.5+mingw32编译生成的动态库(不带world) https://blog.csdn.net/aggs1990/article/details/124166067 CSDN审核可能较慢,如无法下载,可以过段时间再回来看下 仅供相关爱好者交流使用,请于下载...

    OpenCV3.3 mingw64位编译 包含contribute部分,适用于除vc编译器的ide

    总的来说,这个压缩包为使用Mingw编译器的开发者提供了一个完整的OpenCV环境,包括运行时所需的.dll文件、编译时的库文件和头文件,使得在64位Windows环境下进行OpenCV开发变得更加便捷。通过熟练掌握OpenCV的使用,...

    OpenCV-MinGW-Build-OpenCV-4.5.2-x64.zip

    使用MinGW编译OpenCV的好处在于,它允许开发者在不依赖Microsoft Visual Studio的情况下,使用C++标准库进行开发。MinGW编译的OpenCV库可以方便那些偏好轻量级开发环境或者使用非Visual Studio IDE(如Code::Blocks...

    Qt5.15.2+openCV4.5.3+mingw32编译的opencv动态库.7z

    在本文中,我们将深入探讨如何在Windows环境下使用Qt5.15.2、OpenCV4.5.3和MinGW32编译OpenCV动态库。这个压缩包包含的资源是专门为那些对计算机视觉和图像处理感兴趣的开发者设计的,他们可能需要在Qt应用中集成...

    OpenCV3.4.0的Mingw版编译文件

    在本案例中,我们关注的是OpenCV 3.4.0版本的MinGW编译文件,这是专门为在Windows环境下使用MinGW编译器开发C++程序而优化的版本。MinGW(Minimalist GNU for Windows)是一个可自由使用的Windows上的GNU工具集,它...

    opencv4.9.0 源码mingw+vs平台编译的动态库

    使用MinGW编译OpenCV的好处在于它提供了一个轻量级的编译环境,并且与开源社区紧密相连,使得开发者能够免费获取和使用编译工具。 另一方面,Visual Studio是Microsoft提供的一个强大的IDE,支持C++开发,尤其适合...

    OpenCV-MinGW-Build-OpenCV-3.4.1.zip_mingw opencv_opencv mingw版本_

    编译好的 OpenCV(MinGW 版),可供QT使用

    OpenCV-MinGW-Build-OpenCV-3.3.1.zip

    OpenCV使用CMake和MinGW的编译安装及其在Qt配置运行](https://blog.huihut.com/2017/12/03/CompiledOpenCVRunInQt/) ## Using OpenCV in Qt Add OpenCV library file and include path to Qt `.pro` file. * My ...

    MinGW编译的opencv4.7版本

    这个压缩包“MinGW编译的opencv4.7版本”意味着它包含了使用MinGW编译器构建的OpenCV库,适用于在Windows系统上进行开发。 OpenCV 4.7版是该库的一个较新版本,提供了许多改进和新功能。在这一版本中,开发者可以...

    OpenCV 3.2.0 使用minGW编译过程及问题解决

    在本文中,我们将深入探讨如何在Windows环境下使用mingw-w64编译OpenCV 3.2.0库。OpenCV(开源计算机视觉库)是一个强大的工具,广泛应用于图像处理和计算机视觉领域。mingw-w64是GCC(GNU Compiler Collection)的...

    OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib-32bit.zip

    这个压缩包"OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib-32bit.zip"是专为在Windows环境下使用MinGW编译器进行C++开发而准备的。MinGW(Minimalist GNU for Windows)是一个小型的GNU开发工具集,它提供了一个不...

    opencv3.4.12 mingw32版本库

    标题中的"opencv3.4.12 mingw32版本库"表明这是一个针对OpenCV 3.4.12版本的特定构建,专为在Windows操作系统上使用MinGW编译环境的应用程序开发。这个版本的OpenCV包含了库文件(.a文件)和头文件(.h文件),它们...

Global site tag (gtag.js) - Google Analytics