2016-04-03 60 views
1

你好我使用aruco時出錯。我只是想從教程的工作中得到一個例子。我根據教程做的一切,但我得到:阿魯科教程代碼不能編譯

/home/pi/Programs/markerDetection/markerDetection.cpp: In function ‘int main(int, char**)’: 
/home/pi/Programs/markerDetection/markerDetection.cpp:26:104: error: invalid initialization of reference of type ‘cv::Ptr<cv::aruco::Dictionary>&’ from expression of type ‘cv::aruco::Dictionary’ 
    aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds, parameters, rejectedCandidates); 
                             ^
In file included from /home/pi/Programs/markerDetection/markerDetection.cpp:6:0: 
/home/pi/opencv/include/opencv2/aruco.hpp:176:19: note: in passing argument 2 of ‘void cv::aruco::detectMarkers(cv::InputArray, cv::Ptr<cv::aruco::Dictionary>&, cv::OutputArrayOfArrays, cv::OutputArray, const cv::Ptr<cv::aruco::DetectorParameters>&, cv::OutputArrayOfArrays)’ 
CV_EXPORTS_W void detectMarkers(InputArray image, Ptr<Dictionary> &dictionary, OutputArrayOfArrays corners, 
       ^
CMakeFiles/marker.dir/build.make:54: recipe for target 'CMakeFiles/marker.dir/markerDetection.cpp.o' failed 
make[2]: *** [CMakeFiles/marker.dir/markerDetection.cpp.o] Error 1 
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/marker.dir/all' failed 
make[1]: *** [CMakeFiles/marker.dir/all] Error 2 
Makefile:76: recipe for target 'all' failed 
make: *** [all] Error 2 

我的代碼是:

#include "opencv2/opencv.hpp" 
#include "opencv2/imgproc/imgproc.hpp" 
#include "opencv2/imgcodecs.hpp" 
#include "opencv2/videoio/videoio.hpp" 
#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/aruco.hpp" 
#include <vector> 

using namespace cv; 
using namespace std; 

int main (int argc, char** argv) 
{ 
     VideoCapture cap; 

     if(!cap.open(0)){ 
       return 0; 
     } 
     for(;;){ 
       Mat inputImage; 
       cap >> inputImage; 
       vector<int> markerIds; 
       vector< vector<Point2f> > markerCorners, rejectedCandidates; 
       aruco::DetectorParameters parameters; 
       aruco::Dictionary dictionary = aruco::getPredefinedDictionary(aruco::DICT_6X6_250); 
       aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds, parameters, rejectedCandidates); 
       Mat outputImage; 
       aruco::drawDetectedMarkers(outputImage, markerCorners, markerIds); 
       if(inputImage.empty()) break; 
       imshow("Webcam", outputImage); 
       if(waitKey(1) >= 0) break; 
     } 

     return 0; 
} 

我知道有太多的包括和代碼需要一些工作,但我只需要它來編譯和我不知道那裏發生了什麼。功能是否改變了?

+0

能夠 你在編譯時會收到異常嗎? –

+1

@TahTatsumoto它在問題的頂部。從錯誤信息看來,必須將字典包裝在一個'cv :: Ptr '中,除非他們參與了一些buffoonery,[這與我看到的不一樣最近的文檔](http://docs.opencv.org/3.1.0/d9/d6a/group__aruco.html#ga306791ee1aab1513bc2c2b40d774f370&gsc.tab=0)。我也沒有看到3.0文檔中的aruco,所以它可能會在早期開發中發生顛簸。 – user4581301

+0

嘿,我包括'cv :: Ptr dictionaryPtr(&字典)'和參數相同,並在函數中使用。現在它可以工作,但是我仍然遇到麻煩,因爲當程序結束時,我得到一個'numpad_chunk():無效指針......'。我知道我正在使用Ptr錯誤,但我不知道發生了什麼。 – Martinator

回答

0

我和你有同樣的問題。這裏是沒有的伎倆:

代替:

aruco::DetectorParameters parameters; 
aruco::Dictionary dictionary=aruco::getPredefinedDictionary(aruco::DICT_6X6_250); 

使用:

cv::Ptr<aruco::DetectorParameters> parameters; 
cv::Ptr<aruco::Dictionary> dictionary=aruco::getPredefinedDictionary(aruco::DICT_6X6_250); 

我希望它可以幫助你。

0

下面的代碼對我的作品:

字典聲明:

cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); 

由於getPredefinedDictionary返回Ptr<Dictionary>http://docs.opencv.org/trunk/d9/d6a/group__aruco.html

爲了檢測標記功能:

cv::aruco::detectMarkers(gray, dictionary, marker_corners, marker_ids);