台灣最大程式設計社群網站
線上人數
1271
 
會員總數:242291
討論主題:187373
歡迎您免費加入會員
討論區列表 >> C/C++ >> c++ dll
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
c++ dll
價值 : 200 QP  點閱數:231 回應數:0

樓主

瓦里安
門外漢
0 1
4 0
發送站內信

請問我手上有一段程式,我想把它包成dll,其中有使用opencv函式庫

#include <opencv2/opencv.hpp>

using namespace cv;
using std::cout;


int main () {
VideoCapture cap(0);

if(!cap.isOpened()){
cout << "Errore"; return -1;
}
Mat3b frame;
while(cap.read(frame)){

/* THRESHOLD ON HSV*/
cvtColor(frame, frame, CV_BGR2HSV);
GaussianBlur(frame, frame, Size(7,7), 1, 1);
//medianBlur(frame, frame, 15);
for(int r=0; r<frame.rows; ++r){
for(int c=0; c<frame.cols; ++c)
// 0<H<0.25 - 0.15<S<0.9 - 0.2<V<0.95
if( (frame(r,c)[0]>5) && (frame(r,c)[0] < 17) && (frame(r,c)[1]>38) && (frame(r,c)[1]<250) && (frame(r,c)[2]>51) && (frame(r,c)[2]<242) ); // do nothing
else for(int i=0; i<3; ++i) frame(r,c)[i] = 0;
}


Mat1b frame_gray;
cvtColor(frame, frame, CV_HSV2BGR);
cvtColor(frame, frame_gray, CV_BGR2GRAY);
threshold(frame_gray, frame_gray, 60, 255, CV_THRESH_BINARY);
morphologyEx(frame_gray, frame_gray, CV_MOP_ERODE, Mat1b(3,3,1), Point(-1, -1), 3);
morphologyEx(frame_gray, frame_gray, CV_MOP_OPEN, Mat1b(7,7,1), Point(-1, -1), 1);
morphologyEx(frame_gray, frame_gray, CV_MOP_CLOSE, Mat1b(9,9,1), Point(-1, -1), 1);

medianBlur(frame_gray, frame_gray, 15);
imshow("Threshold", frame_gray);

cvtColor(frame, frame, CV_BGR2HSV);
resize(frame, frame, Size(), 0.5, 0.5);
imshow("Video",frame);


waitKey(5);
}
}


我在之前有找過網路上包dll的教學,不過都是簡單的4則運算跟文字表示,我不太知道要怎麼包,不過我有硬塞看看,但編譯不過

硬塞的:
/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>
//膚色偵測1
#include <opencv2/opencv.hpp>


void DllClass::HelloWorld()
{
using namespace cv;
using std::cout;

VideoCapture cap(0);

Mat3b frame;
while(cap.read(frame)){

/* THRESHOLD ON HSV*/
cvtColor(frame, frame, CV_BGR2HSV);
GaussianBlur(frame, frame, Size(7,7), 1, 1);
//medianBlur(frame, frame, 15);
for(int r=0; r<frame.rows; ++r){
for(int c=0; c<frame.cols; ++c)
// 0<H<0.25 - 0.15<S<0.9 - 0.2<V<0.95
if( (frame(r,c)[0]>5) && (frame(r,c)[0] < 17) && (frame(r,c)[1]>38) && (frame(r,c)[1]<250) && (frame(r,c)[2]>51) && (frame(r,c)[2]<242) ); // do nothing
else for(int i=0; i<3; ++i) frame(r,c)[i] = 0;
}


Mat1b frame_gray;
cvtColor(frame, frame, CV_HSV2BGR);
cvtColor(frame, frame_gray, CV_BGR2GRAY);
threshold(frame_gray, frame_gray, 60, 255, CV_THRESH_BINARY);
morphologyEx(frame_gray, frame_gray, CV_MOP_ERODE, Mat1b(3,3,1), Point(-1, -1), 3);
morphologyEx(frame_gray, frame_gray, CV_MOP_OPEN, Mat1b(7,7,1), Point(-1, -1), 1);
morphologyEx(frame_gray, frame_gray, CV_MOP_CLOSE, Mat1b(9,9,1), Point(-1, -1), 1);

medianBlur(frame_gray, frame_gray, 15);
imshow("Threshold", frame_gray);

cvtColor(frame, frame, CV_BGR2HSV);
resize(frame, frame, Size(), 0.5, 0.5);
imshow("Video",frame);


waitKey(5);
}
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
{
break;
}
case DLL_PROCESS_DETACH:
{
break;
}
case DLL_THREAD_ATTACH:
{
break;
}
case DLL_THREAD_DETACH:
{
break;
}
}

/* Return TRUE on success, FALSE on failure */
return TRUE;
}


錯誤如下:

C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\bin\ld.exe skipping incompatible D:/opencv2.4.9/opencv/build/x86/vc12/lib/opencv_imgproc249.lib when searching for -lopencv_imgproc249
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\bin\ld.exe skipping incompatible D:/opencv2.4.9/opencv/build/x86/vc12/lib/opencv_imgproc249.lib when searching for -lopencv_imgproc249
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\bin\ld.exe skipping incompatible D:/opencv2.4.9/opencv/build/x86/vc12/lib\opencv_imgproc249.lib when searching for -lopencv_imgproc249
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\bin\ld.exe cannot find -lopencv_imgproc249
D:\專題\helloworld\collect2.exe [Error] ld returned 1 exit status
27 D:\專題\helloworld\Makefile.win recipe for target 'helloworld.dll' failed


搜尋相關Tags的文章: [ c++ ] , [ dll ] , [ opencv ] ,
本篇文章發表於2017-12-20 14:41
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
目前尚無任何回覆
   

回覆
如要回應,請先登入.