将VB.net代码改为VB6代码

美薇 2017-02-20 09:51:29
'最近需要用VB6对别人提供的的人脸识别SDK进行编程,没有VB6例程,只有vb.NET例程和部分说明,本人初学不久,求高人将下面例程改为VB6代码,不胜感激。
'vb.net Module1.vb 代码:
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.Text
Module Module1
<DllImport("FTDetectAPI.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> Public Function ftInitSDK(ByVal ipAddr As String, ByVal port As Long) As Integer
End Function
<DllImport("FTDetectAPI.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> Public Function ftDetectFaces _
(ByVal chn As Integer, ByVal pbyJpgSrcF1() As Byte, ByVal lenF1 As Integer, ByRef outData As IntPtr, ByRef facenum As Integer) As Integer
End Function
<DllImport("FTDetectAPI.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> Public Function ftDetectFaces1 _
(ByVal chn As Integer, ByVal filename As String, ByVal outData() As Integer, ByRef facenum As Integer) As Integer
End Function
<DllImport("FTDetectAPI.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> Public Sub ftUnInitSDK()
End Sub
<DllImport("FTDetectAPI.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> Public Function ftVerifyImage(ByVal pbyJpgSrcF0() As Byte, ByVal lenF0 As Integer, _
ByVal pbyJpgSrcF1() As Byte, ByVal lenF1 As Integer, ByRef score As Single) As Integer
End Function
<DllImport("FTDetectAPI.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> Public Function ftGetImageFeature(ByVal pbyJpgSrcF0() As Byte, ByVal lenF0 As Integer, _
ByVal feature() As Byte, ByRef lenOut As Integer) As Integer
End Function
<DllImport("FTDetectAPI.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> Public Function ftRegistPerson(ByVal regId As Integer, _
ByVal feature() As Byte, ByVal len As Integer) As Integer
End Function
<DllImport("FTDetectAPI.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> Public Function ftDeletePerson(ByVal regId As Integer) As Integer
End Function
<DllImport("FTDetectAPI.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.StdCall)> Public Function ftQueryPerson(ByVal feature() As Byte, ByVal len As Integer, _
ByVal maxReturn As Integer, ByVal thresh As Double, ByVal outPersonBuffer() As Byte, ByVal outPersonBufferLen As Integer) As Integer
End Function

Function ReadImageFile(file As String, ByRef Dat() As Byte, ByRef Len As Long)
FileOpen(1, file, OpenMode.Binary)
Len = LOF(1)
ReDim Dat(Len - 1)
FileGet(1, Dat)
FileClose(1)
If (Len > 0) Then
Return 0
End If
Return -1
End Function
Sub Main()
Dim ret As Integer
Console.WriteLine("开始初始化链接")
ret = ftInitSDK("127.0.0.1", 9898)
If (ret >= 0) Then
Console.WriteLine("初始化链接成功!")
ElseIf ret = -1 Then
Console.WriteLine("动态库模块加载失败!")
ElseIf ret = -10 Then
Console.WriteLine("链接人脸识别服务程序失败!")
End If
Dim imgDat0() As Byte
Dim imgLen0 As Long
Dim imgDat1() As Byte
Dim imgLen1 As Long
Dim imgDat2() As Byte
Dim imgLen2 As Long
ReadImageFile("../images/face_00.jpg", imgDat0, imgLen0)
ReadImageFile("../images/face_01.jpg", imgDat1, imgLen1)
ReadImageFile("../images/face_02.jpg", imgDat2, imgLen2)
Console.WriteLine("=========================================================")
Console.WriteLine("开始测试人脸检测函数")
'演示人脸检测功能
'从照片中检测人脸位置坐标

Dim outData As IntPtr
Dim facenum As Integer
Dim detResult(1024) As Integer
ret = ftDetectFaces(0, imgDat0, imgLen0, outData, facenum)
If ret >= 0 And facenum > 0 Then
For i = 0 To facenum - 1
Dim myint As Integer = Marshal.ReadInt32(outData, i * 5)
Dim x As Integer = Marshal.ReadInt32(outData, (i * 5 + 1) * Len(myint))
Dim y As Integer = Marshal.ReadInt32(outData, (i * 5 + 2) * Len(myint))
Dim width As Integer = Marshal.ReadInt32(outData, (i * 5 + 3) * Len(myint))
Dim height As Integer = Marshal.ReadInt32(outData, (i * 5 + 4) * Len(myint))
Dim info As String
Console.WriteLine()
Console.WriteLine("ID编号:" & myint & "位置:" & x & "," & y & "," & width & "," & height)
Next i
End If
Console.WriteLine("=========================================================")
Console.WriteLine("开始测试1:1人脸比对函数")

'演示1:1人脸比对功能
Dim score As Single
ret = ftVerifyImage(imgDat0, imgLen0, imgDat1, imgLen1, score)
If (ret >= 0) Then
Console.WriteLine("两幅图像1;1测试比对结果:" & score)
End If
Console.WriteLine("=========================================================")
Console.WriteLine("开始测试1:N人脸检索函数")
'演示1:N人脸检索功能
'清空人脸
ftDeletePerson(-1)
'提取特征'从照片中提取人脸特征特征
Dim fea0(8000) As Byte
Dim feaLen0 As Integer
Dim fea1(8000) As Byte
Dim feaLen1 As Integer
Dim fea2(8000) As Byte
Dim feaLen2 As Integer
'ret >=0 正常,否则失败
Console.WriteLine("步骤1:提取3张图片的人脸特征")
ret = ftGetImageFeature(imgDat0, imgLen0, fea0, feaLen0)
ret = ftGetImageFeature(imgDat1, imgLen1, fea1, feaLen1)
ret = ftGetImageFeature(imgDat2, imgLen2, fea2, feaLen2)
'注册人脸 注册N张照片
'ret >=0 表示注册成功

Console.WriteLine("步骤2:往库中注册其中2个特征, 假设它们ID分别为101,102")
ret = ftRegistPerson(101, fea0, feaLen0)
ret = ftRegistPerson(102, fea1, feaLen1)
'查找人脸 通过另一张照片查找101 ID是事存在? 假设过滤阈值为0.85,最多返回20个结果
Console.WriteLine("步骤3:通过101 另一张照片查找ID是否存在? 返回格式为 id,value^id,value^id......")
Dim outPersonBuffer(1024) As Byte
Dim outPersonBufferLen As Integer
'每次使用前,初始化
ReDim outPersonBuffer(1024)
outPersonBufferLen = 1024
ret = ftQueryPerson(fea2, feaLen2, 20, 0.85F, outPersonBuffer, outPersonBufferLen)
If (ret >= 0) Then
Dim reStr As String
reStr = Encoding.ASCII.GetString(outPersonBuffer)
Console.WriteLine("识别结果:" & reStr)
End If

Console.WriteLine("=========================================================")
Console.WriteLine("测试结束!")
Console.ReadLine()

'释放资源
ftUnInitSDK()

End Sub

End Module

下面是C语言头文件说明:


#ifndef _FT_DETECT_API_H_
#define _FT_DETECT_API_H_

// DetectAPI.cpp : 定义控制台应用程序的入口点。
//


#include "stdafx.h"

#define IMAGE_SIZE 1024*1024*8

struct SDS_POINT 结构:
{
float x;
float y;
};
struct FaceObject 定义结构:
{
SDS_POINT lefteye; //左眼坐标
SDS_POINT righteye;
SDS_POINT mouth; //嘴巴坐标
float outLight; //明暗程度
float outSynLight; //光线对称性
float outDiffH; //水平偏转
float outDiffV; //俯仰偏转
float outDiffR; //垂直偏转
float outEyeClosed; //
float outEyeGlass; //眼睛清晰度
float outMouthClosed; //闭嘴程度
float qScore;
};
/*
* 函数名:ftInitSDK
*参数:IP-人脸识别服务所在IP地址;PORT-端口
*返回:-10,表示找不到比对服务;-1表示程序加载失败
*/

int WINAPI ftInitSDK(const char* ip, int port);
void WINAPI ftUnInitSDK();
/*
* 函数名:ftDetectFaces 本地函数

*参数:chn,表示检测通道,即1路视频,同时可开启5路。
*参数:pbyJpgSrcF,表示图片流,即JPG文件以内存数组方式存储;
*参数:lenF,内存图像流,数组的长度
*参数:outData,表示检测到的人脸ID与位置,每5个INT值表示1个人脸,格式为 id,x,y,w,h,id,x,y,w,h,id.......
*参数:facenum, 表示outData中包括的有效人脸个数
*返回:-1表示失败,可能图片有问题;-10网络或后台EXE服务有问题。
*/

int WINAPI ftDetectFaces(int chn, char* pbyJpgSrcF, int lenF, int *&outData, int &facenum);
int WINAPI ftDetectFaces2(int chn, char* pbyJpgSrcF, int lenF, int *&outData, int &facenum);
/*
* 函数名:ftVerifyImage 远程函数
*参数:pbyJpgSrcF,表示图片流,即JPG文件以内存数组方式存储;
*参数:lenF,内存图像流,数组的长度
*参数:score, 图片比对结果[0,1.0], -1表示比对失败
*-1表示失败,可能图片有问题;-10网络或后台EXE服务有问题。
*/

int WINAPI ftVerifyImage(char* pbyJpgSrcF0, int lenF0, char* pbyJpgSrcF1, int lenF1, float &score);
/*
* 函数名:ftGetImageFeature 得到图像的特征值 远程函数

*参数:pbyJpgSrcF,表示图片流,即JPG文件以内存数组方式存储;
*参数:lenF,内存图像流,数组的长度
*参数:outFeature, 在外部申请空间,如char outFeature[4096]
*参数:outLen , 返回实际特征大小
*-1表示失败,可能图片有问题;-10网络或后台EXE服务有问题。
*/
int WINAPI ftGetImageFeature(char* pbyJpgSrcF, int lenF, char *outFeature, int &outLen);
/*
* 函数名:ftRegistPerson 1;N往内存注册特征值 远程函数
*参数:id, 该人的唯一ID 定义时必须大于0
*参数:feature,特征值;
*参数:len,特征值长度;
*-1表示失败,可能图片有问题;-10网络或后台EXE服务有问题。
*/

int WINAPI ftRegistPerson(int id, const char *feature, int len);
int WINAPI ftDeletePerson(int id); //-1表示清空所有记录
int WINAPI ftUpdatePerson(int id, const char *feature, int len);//暂未使用
/*
* 函数名:ftQueryPerson 1;N查询与指定特征值相似的人 远程函数
*参数:feature,特征值;
*参数:len,特征值长度;
*参数:maxReturn, 返回相似的最多人数
*参数:threshHold, 返回的人应满足的阈值条件
*参数:outPersonBuffer, 外部申请空间,如char outPersonBuffer[10000]; 返回的人ID与相似度值,格式为 id,value^id,value^id.......
*参数:outPersonBufferLen = 10000, 指明外部空间大小
*-1表示失败,可能图片有问题;-10网络或后台EXE服务有问题。
*/

int WINAPI ftQueryPerson(const char *feature, int len, int maxReturn, double threshHold, char *outPersonBuffer, int outPersonBufferLen);
...全文
5375 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
美薇 2017-02-26
  • 打赏
  • 举报
回复
正在学习,谢谢大家
赵4老师 2017-02-21
  • 打赏
  • 举报
回复
建议楼主抽空学习一下VB.NET
Tiger_Zhao 2017-02-21
  • 打赏
  • 举报
回复
具体工作不想自己做就出钱外包。
ah_2056 2017-02-21
  • 打赏
  • 举报
回复
引用 1 楼 caozhy 的回复:
vb.net编译成dll,comvisible为true,用regasm注册,vb添加工程引用,然后调用。
最好的办法。
threenewbee 2017-02-21
  • 打赏
  • 举报
回复
vb.net编译成dll,comvisible为true,用regasm注册,vb添加工程引用,然后调用。

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧