導航:首頁 > 源碼編譯 > 編譯opencv常式

編譯opencv常式

發布時間:2024-03-27 16:21:41

Ⅰ 在ARM上運行交叉編譯後的opencv文件,沒有輸出

一、交叉編譯opencv
構造:

下載:各個庫的下載可以直接搜名字到官網下載
幾個關鍵解釋:
「--prefix=」 後邊跟make install時的位置,本例中,libz在make install時將安裝到/usr/arm-linux-gnueabihf中
「--host=」 後邊跟arm-linux表明使用的是ARM環境
有configure的才能進行configure配置
4)所有的makefile修改類似
Libz的交叉編譯
第一步:# ./configure --prefix=/usr/arm-linux-gnueabihf --shared
第二步:修改makefile,主要有下邊幾個,修改的時候通篇參照即可
CC=arm-linux-gnueabihf-gcc
AR=arm-linux-gnueabihf-ar rc
RANLIB=arm-linux-gnueabihf-ranlib
STRIP = arm-linux-gnueabihf-strip
如果有ARCH的話,ARCH=ARM
第三步:#sudo make
#sudo make install
Libjpeg的交叉編譯
第一步:#./configure --host=arm-linux --prefix=/usr/arm-linux-gnueabihf --enable-shared --enable-static CC=arm-linux-gnueabihf-gcc
第二步:參考1)中方法修改makefile
第三步:#sudo make
#sudo make install
Libpng的交叉編譯
第一步:#./configure --host=arm-linux --prefix=/usr/arm-linux-gnueabihf --enable-shared --enable-static CC=arm-linux-gnueabihf-gcc
第二步:參考1)中方法修改makefile
第三步:#sudo make
#sudo make install
Yasm的交叉編譯
第一步:#./configure --host=arm-linux --prefix=/usr/arm-linux-gnueabihf --enable-shared --enable-static
第二步:修改makefile
第三步:#sudo make
#sudo make install
Libx264的交叉編譯
第一步:#CC=arm-linux-gnueabihf-gcc ./configure --enable-shared --host=arm-linux --disable-asm --prefix=/usr/arm-linux-gnueabihf
第二步:修改config.mak里的參數,因為makefile要調用config.mak,所以修改方法同makefile
第三步:#sudo make
#sudo make install
Libxvid的交叉編譯
第一步:首先切換目錄 #cd build/generic
第二步:#./configure --prefix=/usr/arm-linux-gnueabihf --host=arm-linux --disable-assembly
第三步:#sudo make
#sudo make install
ffmpeg的交叉編譯
第一步:
./configure --enable-cross-compile --target-os=linux --cc=arm-linux-gnueabihf-gcc --arch=arm --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-ffmpeg --disable-ffplay --enable-ffserver --enable-swscale --enable-pthreads --disable-yasm --disable-stripping --enable-libx264 --enable-libxvid --extra-cflags=-I/usr/arm-linux-gnueabihf/include --extra-ldflags=-L/usr/arm-linux-gnueabihf/lib --prefix=/usr/arm-linux-gnueabihf
第二步:修改makefile文件
第三步:#sudo make
#sudo make install
第四步:將ffmpeg加入pkg-config
執行#sudo gedit /etc/bash.bashrc,在末尾加入
export LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib/
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/arm-linux-gnueabihf /lib/pkgconfig
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR:/usr/arm-linux-gnueabihf /lib/
完畢後使用命令:#source /etc/bash.bashrc
或者單獨使用三個export,不過壽命只在一個終端中,終端關閉時就失效。
幾個關鍵解釋:--extra-flags指向xvid的安裝路徑,--extra-ldflags指向x264的路徑
安裝cmake-gui
執行:#sudo apt-get install cmake-qt-gui
Opencv的交叉編譯
第一步:修改opencv/platflrms/linux/目錄下的arm-gnueabi.toolchain.cmake,將其所有刪掉,寫入:
set( CMAKE_SYSTEM_NAME Linux )
set( CMAKE_SYSTEM_PROCESSOR arm )
set( CMAKE_C_COMPILER arm-linux-gnueabihf-gcc )
set( CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++ )
第二步:在opencv目錄下新建build目錄,進入build目錄,執行命令:
#cmake -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake ../
這時,要保證出現:

第三步:使用cmake-gui打開CMakeCache.txt,去掉所有的無關項,修改CMAKE_INSTALL_PREFIX,來確定make install的目錄
第四步:#sudo make
#sudo make install
可能出現的錯誤:
opencv編譯不通過,出現skip之類的,說明ffmpeg沒編譯好,或者其編譯好了,但是pkg-config沒有設置好,一定要設置好其環境
前邊幾步不通過的話,看看命令有沒有少,或者有沒有修改好makefile
在arm上使用時,一種方法時直接將編譯好的opencv目錄下的lib文件拷貝到開發板對應的/lib目錄下,其他或者拷貝到自己指定的目錄,並設置好環境變數即可使用

Ⅱ 在ubantu12.04版本環境下,使用交叉編譯工具編譯opencv,老出現這個問題,求大神指教!

整個項目的結構圖:

編寫DetectFaceDemo.java,代碼如下:

[java] view
plainprint?

package com.njupt.zhb.test;

import org.opencv.core.Core;

import org.opencv.core.Mat;

import org.opencv.core.MatOfRect;

import org.opencv.core.Point;

import org.opencv.core.Rect;

import org.opencv.core.Scalar;

import org.opencv.highgui.Highgui;

import org.opencv.objdetect.CascadeClassifier;

//

// Detects faces in an image, draws boxes around them, and writes the results

// to "faceDetection.png".

//

public class DetectFaceDemo {

public void run() {

System.out.println("\nRunning DetectFaceDemo");

System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());

// Create a face detector from the cascade file in the resources

// directory.

//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("森段並lbpcascade_frontalface.xml").getPath());

//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());

//注意:源程序的路徑會多列印一個燃豎『/』,因此總是出現如下錯誤

/*

* Detected 0 faces Writing faceDetection.png libpng warning: Image

* width is zero in IHDR libpng warning: Image height is zero in IHDR

* libpng error: Invalid IHDR data

*/

//因此,我們將第一個字元去掉

String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);

CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);

Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));

// Detect faces in the image.

// MatOfRect is a special container class for Rect.

MatOfRect faceDetections = new MatOfRect();

faceDetector.detectMultiScale(image, faceDetections);

System.out.println(String.format("此跡Detected %s faces", faceDetections.toArray().length));

// Draw a bounding box around each face.

for (Rect rect : faceDetections.toArray()) {

Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));

}

// Save the visualized detection.

String filename = "faceDetection.png";

System.out.println(String.format("Writing %s", filename));

Highgui.imwrite(filename, image);

}

}
package com.njupt.zhb.test;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;

//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
public class DetectFaceDemo {
public void run() {
System.out.println("\nRunning DetectFaceDemo");
System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());
// Create a face detector from the cascade file in the resources
// directory.
//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());
//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());
//注意:源程序的路徑會多列印一個『/』,因此總是出現如下錯誤
/*
* Detected 0 faces Writing faceDetection.png libpng warning: Image
* width is zero in IHDR libpng warning: Image height is zero in IHDR
* libpng error: Invalid IHDR data
*/
//因此,我們將第一個字元去掉
String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);
CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);
Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));
// Detect faces in the image.
// MatOfRect is a special container class for Rect.
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);

System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));

// Draw a bounding box around each face.
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
}

// Save the visualized detection.
String filename = "faceDetection.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}
}

3.編寫測試類:

[java] view
plainprint?

package com.njupt.zhb.test;

public class TestMain {

public static void main(String[] args) {

System.out.println("Hello, OpenCV");

// Load the native library.

System.loadLibrary("opencv_java246");

new DetectFaceDemo().run();

}

}

//運行結果:

//Hello, OpenCV

//

//Running DetectFaceDemo

///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml

//Detected 8 faces

//Writing faceDetection.png
package com.njupt.zhb.test;
public class TestMain {
public static void main(String[] args) {
System.out.println("Hello, OpenCV");
// Load the native library.
System.loadLibrary("opencv_java246");
new DetectFaceDemo().run();
}
}
//運行結果:
//Hello, OpenCV
//
//Running DetectFaceDemo
///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml
//Detected 8 faces
//Writing faceDetection.png

Ⅲ cv2.error: /io/opencv/moles/imgproc/src/color.cpp:10638: error: (-215) scn == 3 || scn == 4 i

1. 編譯第一個opencv程序,出現了如下的錯誤。

[plain]view plain

Ⅳ 如何編譯opencv中的install工程

第一步:由於opencv是在cmake工具下建立的工程,所以我們先要下載cmake,下載地址隨便一搜都有,不多說。下載到home的主目錄下,這里我們是/home/lg。看下面的命令:#cd /home/lg#tar xzvf CMake2.4.7.tar.gz .#cd CMake2.4.7#./boostrap#gmake#make install這樣cmake工具安裝好了,並且可以直接使用cmake命令根據cmake的編譯規律,我們選擇外部編譯。
2
下載Opencv2.3.0到/home/lg解壓後進入Opencv2.3.0的目錄下(這里的opencv與以前版本1.0的不一樣,沒有configure文件,所以我們執行不了 ./configure命令) :#mkdir build#cd build#cmake -D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON.. (這條命令解析可以參考cmake教程, 但是記住這里的第二個選項,我們將opencv安裝在/usr/local目錄下的)#make#make install到這opencv編譯完成,接下去看看opencv這個工具能正常使用。
3
記住這里的做法前一種對fedora有用, 也就是說在fedora的環境下只能使用這種做法, 但是ubuntu卻可以使用兩種方法。 順便說一下, 經常遇見apt-get命令,這是在ubuntu下使用獲取軟體包的命令, fedora使用的是yum, 記住了, 否則經常出現使用apt-get卻獲取不了軟體包的情況。方法1:在/etc/ld.so.conf.d下新建一個文件opencv.conf,裡面輸入/usr/local/lib方法2:在/etc/ld.so.conf文件中加入/usr/local/lib這一行然後執行#ldconfig(root許可權下)#cp /usr/local/lib/pkconfig/opencv.pc /usr/lib/pkgconfig(或者是輸入這個命令 exportPKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH)( pkconfig的用法見以前的博文)至此opencv安裝完成我們可以找個例子來做實驗#cd /home/lg/Opencv2.3.0#cd samples/cpp#g++ `pkconfig --cflags --libs opencv` drawing.cpp -odrawing(記住前面的兩個引號是通過ESC下面的那個波浪符鍵獲得的)現在我們編譯那個人臉檢測程序,在Opencv2.3.0/data/目錄下有檢測鼻子、眼睛的XML文件,這可以通過改build目錄下的c目錄下的facedetect文件獲得。#cd ..#cd c#g++ `pkconfig --cflags --libs opencv` facedetect.c -ofacedetect到此結束

Ⅳ opencv如何編譯能支持單片機

可根據如下操作實現。
首先在VS中用C++寫一個串口能信的子程序放到OPENCV的程序中,再寫一個單片機的串口通信程序,最後連接運行即可。

閱讀全文

與編譯opencv常式相關的資料

熱點內容
安卓如何截屏到手機 瀏覽:994
多空資金指標公式源碼精準買點 瀏覽:227
匿名投票小程序源碼 瀏覽:1000
java運行監控 瀏覽:233
成都做程序員之都 瀏覽:537
光纖輸出的是源碼還是pcm 瀏覽:143
pdf格式列印出來是白紙 瀏覽:313
主人公叫葉天明柳韶的小說 瀏覽:74
愛戀一樣電影 瀏覽:661
叮咚浩哥電影叫什麼 瀏覽:675
新世界電訊伺服器怎麼樣 瀏覽:126
美國科幻片機器人 瀏覽:104
韓國推理劇愛情電影 瀏覽:757
電視機上app自動扣費哪裡關 瀏覽:44
影像學pdf 瀏覽:316
教育網電教伺服器是什麼呢 瀏覽:136
小電影網站誰有 瀏覽:327
女主和兩個雙胞胎兄弟 瀏覽:6
備戰方艙老兵給新兵寬心解壓 瀏覽:646
宣城加密加硬珍珠棉生產廠 瀏覽:756