【发布时间】:2011-06-19 01:53:20
【问题描述】:
我一直在研究使用 OpenCV 进行一些跟踪的 DLL。使用 VS 2008(用于测试目的)在 C 控制台项目上完成所有工作。然后我创建了一个新的 DLL 项目并编译它。我设置了所有东西,所以我只在 Thread 类上放了一个函数来调用一个函数。
然后我为 GUI 和其他东西创建了一个 C# 项目。 DLL 加载正常(使用System.Runtime.InteropServices,方法启动(我可以看到 OpenCV 创建的捕获窗口)但没有完成跟踪。为了验证 DLL 是否实际工作,我在 Python 上加载并调用该方法和它运行良好(正在跟踪)。
我不熟悉在托管代码上使用非托管 DLL。关于我做错了什么或如何调试它的任何想法?如果您需要其他任何东西来帮助我解决这个问题,我会提供。
提前致谢。
编辑:
我没有使用 DLL 上的类,我使用的是单个函数,Thread 类来自 C# 上的 System.Threading
我使用DLL的方式是这样的。
namespace GUI
{
static class NativeTracking
{
[DllImport(@"__Tracking.dll")]
public static extern void _Tracking();
}
}
我把它放在像他这样的线程上
public GUI()
{
InitializeComponent();
_tracking = new Thread(_Tracking);
_tracking.Start();
}
public _Tracking()
{
while(True)
{
NativeTracking.Tracking();
}
}
编辑:本机编码
本机代码,抱歉格式混乱。
头文件
#include <cv.h>
#include <stdio.h>
#include <ctype.h>
#include <windows.h>
#include <highgui.h>
#include "..\original\project\myheader.h"
#include "..\original\project\myheader1.h"
#include "..\original\project\myheader2.h"
#include "..\original\project\myheader3.h"
#include "..\original\project\myheader4.h"
#ifdef __cplusplus
extern "C"{
#endif
_declspec(dllexport) void Tracking();
#ifdef __cplusplus
}
#endif
实施
#include "exposed.h"
void Tracking( )
{
int flag = 1, i=0;
iplImgs imgs;
trackingTool tools;
helperTools helperTools;
CvCapture* capture = 0;
capture = cvCaptureFromCAM( 0 );
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 240);
cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, 20.0f);
imgs.image = 0;
cvNamedWindow( "Window", 0 );
initHelperTools(&helperTools);
initTools(&imgs, &tools);
for(;;){
int c;
IplImage* frame = 0;
frame = cvQueryFrame( capture );
if( !frame )
break;
if( !imgs.image ){
/* allocate all the buffers */
prepareImages(&imgs, &tools, frame);
}
cvCopy( frame, imgs.image, 0 );
cvCvtColor( imgs.image, imgs.grey, CV_BGR2GRAY );
if( flag == 1 || conditionB ){
someOperations(&imgs, &tools);
if (conditionC)
flag = 0;
}
else if( conditionD ){
otherOps(&helperTools, imgs.grey);
someTrack(&imgs, &tools, &helperTools, drawPoints);
someCorrections(&tools);
if ( condition ){
if (!wasReset){
wasReset = 0;
continue;
}
if ( validation )
someMoreOperations(&tools, corretions);
}
}
bufferHandlingOps(&imgs);
c = cvWaitKey(10);
if( (char)c == 27 )
break;
switch ((char)c){
case 'p':
drawPoints ^= 1;
break;
default:
;
}
}
cvReleaseCapture( &capture );
cvDestroyWindow("Window");
}
【问题讨论】:
-
C 没有类,所以要么你没有线程类,要么你没有使用 C。
-
我没有使用DLL上的类,我使用的是单个函数,Thread类来自C#上的
System.Threading。 -
您可以编辑问题以包含您的本机“跟踪”方法吗?