2017-02-07 27 views
-1

這是我正在使用的代碼:的std ::上OpenCV的功能線程生成錯誤「試圖使用已刪除的功能」

cv::Mat mask, foreground; 
std::thread t(cv::threshold, mask, foreground, 254, 255, cv::THRESH_BINARY); 
t.join(); 

在Xcode 8編譯與支持C++ 11。有任何想法嗎?

以下是完整的錯誤消息:

In file included from /Users/mlitvin/xcode/Create/ImageProcUtils.cpp:13: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:347:5: error: attempt to use a deleted function __invoke(_VSTD::move(_VSTD::get(__t)), _VSTD::move(_VSTD::get(__t))...); ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:357:5: note: in instantiation of function template specialization 'std::__1::__thread_execute' requested here __thread_execute(*__p, _Index()); ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:369:42: note: in instantiation of function template specialization 'std::__1::__thread_proxy >' requested here int __ec = pthread_create(&__t_, 0, &__thread_proxy, __p.get()); ^ /Users/mlitvin/xcode/Create/ImageProcUtils.cpp:71:21: note: in instantiation of function template specialization 'std::__1::thread::thread' requested here std::thread t(cv::threshold, mask, foreground, 254, 255, cv::THRESH_BINARY); ^ In file included from :368: In file included from :3: In file included from /Users/mlitvin/xcode/Create/Create/Create_Prefix.h:25: In file included from /Users/mlitvin/xcode/Create/3rdParty/OpenCV-2.3.1/modules/imgproc/include/opencv2/imgproc/imgproc.hpp:50: In file included from /Users/mlitvin/xcode/Create/3rdParty/OpenCV-2.3.1/modules/core/include/opencv2/core/core.hpp:56: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:625: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:1087:5: note: '~__nat' has been explicitly marked deleted here ~__nat() = delete; ^ 1 error generated.

編輯1:

貌似問題是與通過cv::OutputArray類型的對象作爲參數。

+2

什麼是完整的錯誤信息?它應該告訴你什麼功能被刪除。 – NathanOliver

+0

我注意到你不會將成員函數的地址傳遞給線程ctor。我期望看到'&cv :: threshold'。也許可能是因爲刪除的函數錯誤信息是一個紅色的鯡魚,你只是有一個語法錯誤。 – acraig5075

+0

'threshold()'不是一個成員函數,它不在類內('cv'是opencv命名空間)。我試圖在'cv :: threshold'之前添加'&',但仍然存在相同的錯誤。 –

回答

0

我設法加入其中僅輸出通過引用傳遞一個代理功能來解決這個問題:

void cv_threshold(cv::Mat _src, cv::Mat& _dst, double thresh, double maxval, int type) { 
    cv::threshold(_src, _dst, thresh, maxval, type); 
} 
... 
cv::Mat mask, foreground; 
std::thread t(cv_threshold, mask, std::ref(foreground), 254, 255, cv::THRESH_BINARY); 
t.join(); 

我會很高興地知道爲什麼原來的方法也沒有工作,雖然 - 會接受解釋這個問題的答案。

相關問題