Dll调用 海康威视网络摄像头
By
cuiqbo
at 2021-06-12 • 1人收藏 • 2247人看过
import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=759;bottom=469)
winform.add(
OpenBtn={cls="button";text="打开";left=542;top=67;right=647;bottom=114;z=3};
S_G_Btn={cls="button";text="开始采集";left=549;top=133;right=654;bottom=180;z=6};
button={cls="button";text="Button";left=600;top=262;right=676;bottom=328;z=7};
button2={cls="button";text="Button";left=645;top=360;right=739;bottom=396;z=8};
closeBtn={cls="button";text="关闭";left=654;top=68;right=742;bottom=112;z=5};
diverListComBox={cls="combobox";left=12;top=6;right=524;bottom=32;edge=1;items={};mode="dropdown";z=4};
emBtn={cls="button";text="枚举";left=541;top=4;right=646;bottom=51;z=1};
picturebox={cls="picturebox";left=9;top=57;right=514;bottom=454;z=2}
)
/*}}*/
var dll = raw.loadDll("~\MvCameraControl.dll");
MV_CC_EnumDevices= dll.api("MV_CC_EnumDevices","INT (INT nTLayerType, struct& pstDevList)");
MV_MAX_GENTL_IF_NUM = 256;
MV_MAX_DEVICE_NUM = 0x100;
//GigE设备信息
class MV_GIGE_DEVICE_INFO {
INT nIpCfgOption; // IP配置选项
INT nIpCfgCurrent; // 当前IP配置
INT nCurrentIp; // 当前IP地址
INT nCurrentSubNetMask; // 当前子网掩码
INT nDefultGateWay; // 当前网关
BYTE chManufacturerName[32]; // 制造商名称
BYTE chModelName[32]; //型号名称
BYTE chDeviceVersion[32]; // 设备版本
BYTE chManufacturerSpecificInfo[48];// 制造商的具体信息
BYTE chSerialNumber[16]; // 序列号
BYTE chUserDefinedName[16]; // 用户自定义名称
INT nNetExport; //网口IP地址
INT nReserved[4]; // 预留
_struct_aligned = 1;
}
// USB设备信息
class MV_USB3_DEVICE_INFO {
BYTE CrtlInEndPoint; //控制输入端点
BYTE CrtlOutEndPoint; //控制输出端点
BYTE StreamEndPoint; //流端点
BYTE EventEndPoint; //事件端点
WORD idVendor; //供应商ID号
WORD idProduct; //产品ID号
INT nDeviceNumber; //设备序列号
BYTE chDeviceGUID [64]; //设备GUID号
BYTE chVendorName [64]; //供应商名字
BYTE chModelName [64]; //型号名字
BYTE chFamilyName[64]; //家族名字
BYTE chDeviceVersion[64]; //设备版本
BYTE chManufacturerName[64]; //制造商名字
BYTE chSerialNumber[64]; //序列号
BYTE chUserDefinedName[64]; //用户自定义名字
INT nbcdUSB; //支持的USB协议
INT nDeviceAddress; //设备地址
INT nReserved[2]; // 预留
_struct_aligned = 1;
}
// CameraLink设备信息
class MV_CamL_DEV_INFO {
BYTE chPortID[64]; //端口号
BYTE chModelName[64]; //型号名字
BYTE chFamilyName[64]; //名称
BYTE chDeviceVersion[64]; //设备版本
BYTE chManufacturerName[64]; //制造商名字
BYTE chSerialNumber[64]; //序列号
INT nReserved[38];
_struct_aligned = 1;
}
// 设备信息
class MV_CC_DEVICE_INFO {
WORD nMajorVer; //主要版本
WORD nMinorVer; //次要版本
INT nMacAddrHigh; //高MAC地址
INT nMacAddrLow; //低MAC地址
INT nTLayerType; //设备传输层协议类型,e.g. MV_GIGE_DEVICE
INT nReserved[4]; // 预留
BYTE SpecialInfo[540];
_struct_aligned = 1; //在结构体中可以使用成员 _struct_aligned 自定义对齐大小。
};
// 通过GenTL枚举到的Interface信息
class MV_GENTL_IF_INFO {
BYTE chInterfaceID[64]; // GenTL接口ID
BYTE chTLType[64]; // 传输层类型
BYTE chDisplayName[64]; // Interface显示名称
INT nCtiIndex; // GenTL的cti文件索引
INT nReserved[8]; //预留
_struct_aligned = 1;
}
class MV_CC_DEVICE_INFO_LIST {
INT DeviceNum; //设备数量
pointer pDeviceInfo[255]; //
};
//输出帧的信息
class MV_FRAME_OUT_INFO_EX {
WORD nWidth; //图像宽
WORD nHeight; //图像高
INT enPixelType; //像素格式
INT nFrameNum; //帧号
INT nDevTimeStampHigh; //时间戳高32位
INT nDevTimeStampLow; //时间戳低32位
INT nReserved0; //保留,8字节对齐
double nHostTimeStamp; //主机生成的时间戳
INT nFrameLen; //帧的长度
//设备水印时标
INT nSecondCount; //秒数
INT nCycleCount; //周期数
INT nCycleOffset; //周期偏移量
float fGain; //增益
float fExposureTime; //曝光时间
INT nAverageBrightness; //平均亮度
//白平衡相关
INT nRed; //红色
INT nGreen; //绿色
INT nBlue; //蓝色
INT nFrameCounter; //总帧数
INT nTriggerIndex; //触发计数
INT nInput; //输入
INT nOutput; //输出
// ROI区域
WORD nOffsetX; //水平偏移量
WORD nOffsetY; //垂直偏移量
WORD nChunkWidth; //Chunk宽
WORD nChunkHeight; //Chunk高
INT nLostPacket; //本帧丢包数
INT nUnparsedChunkNum; //未解析的Chunkdata个数
BYTE UnparsedChunkLis[8];
INT nReserved[36]; // 预留
_struct_aligned = 1;
}
//图片保存参数
class MV_SAVE_IMAGE_PARAM_EX {
pointer pData; //输入数据缓存
INT nDataLen; //输入数据大小
INT enPixelType; //输入数据的像素格式
WORD nWidth; //图像宽
WORD nHeight; //图像高
pointer pImageBuffer; //输出图片缓存
INT nImageLen; //输出图片大小
INT nBufferSize; //提供的输出缓冲区大小
INT enImageType; //输出图片格式
INT nJpgQuality; //JPG编码质量(50-99],其它格式无效
//Bayer的插值方法 0-快速 1-均衡 2-最优(如果传入其它值则默认为最优)
INT iMethodValue; //插值方法
INT nReserved[3]; //预留
_struct_aligned = 1;
}
var stDeviceInfo = MV_CC_DEVICE_INFO();
m_stDevList = MV_CC_DEVICE_INFO_LIST();
//console.dump("您输入的是" ,s);
var pt ={pointer p;};
MV_SAVE_IAMGE_TYPE ={
MV_Image_Undefined = 0, //未定义的图像格式
MV_Image_Bmp = 1, //BMP图像格式
MV_Image_Jpeg = 2, //JPEG图像格式
MV_Image_Png = 3, //PNG图像格式
MV_Image_Tif = 4, //TIFF图像格式
};
class MVCC_INTVALUE {
INT nCurValue; // 当前值
INT nMax; // 最大值
INT nMin; // 最小值
INT nInc;
INT nReserved[4]; ///< \~chinese 预留
}
function GetOneFrameTimeout ( pData, nDataSize, pFrameInfo, nMsec)
{
return MV_CC_GetOneFrameTimeout(m_hDevHandle, pData, nDataSize, pFrameInfo, nMsec);
}
winform.emBtn.oncommand = function(id,event){
var EnumDevices= dll.MV_CC_EnumDevices(1 or 4, m_stDevList );
//dll.MV_CC_StartGrabbin();
for(i=1;m_stDevList.DeviceNum;1){
var s = raw.convert(m_stDevList.pDeviceInfo[i],stDeviceInfo);
var TLayerType = s.nTLayerType;
var DInfo,title;
win.delay(1);
if(TLayerType=1){
DeviceInfo = MV_GIGE_DEVICE_INFO();
title = "GIGE";
}
if(TLayerType=4){
DeviceInfo = MV_USB3_DEVICE_INFO();
title = "USB";
}
var DeviceInfo = raw.convert(s.SpecialInfo,MV_GIGE_DEVICE_INFO())
win.delay(1);
var ip =DeviceInfo.nCurrentIp;
//console.dump(DeviceInfo)
win.delay(1);
var nIp1, nIp2, nIp3, nIp4 = (ip & 0xff000000) >>24,(ip & 0x00ff0000) >>16,(ip & 0x0000ff00) >>8,ip & 0xff;
win.delay(1);
winform.diverListComBox.add(string.format("%s:%s(%d.%d.%d.%d)",title , DeviceInfo.chUserDefinedName,nIp1, nIp2, nIp3, nIp4),-1)
}
}
winform.OpenBtn.oncommand = function(id,event){
var nRet = dll.MV_CC_CreateHandle(pt,m_stDevList.pDeviceInfo[winform.diverListComBox.selIndex]);
if( 0 != nRet )error("连接错误!");
nRet = dll.MV_CC_OpenDevice(pt.p, 1, 0)
win.msgbox(nRet)
}
winform.closeBtn.oncommand = function(id,event){
if(pt.p){
nRet = dll.MV_CC_StopGrabbing(pt.p)
nRet = dll.MV_CC_CloseDevice(pt.p)
nRet = dll.MV_CC_DestroyHandle(pt.p)
}
}
winform.S_G_Btn.oncommand = function(id,event){
nRet = dll.MV_CC_StartGrabbing(pt.p)
nRet = dll.MV_CC_Display(pt.p,winform.picturebox.hwnd)
win.msgbox(nRet)
}
import console;
var stIntValue =MVCC_INTVALUE();
console.open()
MV_CC_GetOneFrameTimeout= dll.api("MV_CC_GetOneFrameTimeout","INT ( pointer handle, string& pData ,INT nDataSize,struct& pstFrameInfo, INT nMsec)");
//MV_CC_SaveImageEx2= dll.api("MV_CC_SaveImageEx2","int( pointer handle, struct& pstSaveParam)");
winform.button.oncommand = function(id,event){
//nSaveImageNeedSize = m_nBufSizeForDriver * 3 + 2048
nRet = dll.MV_CC_GetIntValueEx(pt.p,"PayloadSize", stIntValue);
stParam = MV_SAVE_IMAGE_PARAM_EX();
stFrameInfo = MV_FRAME_OUT_INFO_EX()
//MAX_BUF = 68157440;
var pData =stIntValue.nCurValue;
var ppData = raw.buffer(pData);
var pDatas ={pointer a;};
nRet,s,s1= MV_CC_GetOneFrameTimeout(pt.p, raw.buffer(pData) , pData, stFrameInfo, 1000);
stParam.enImageType = 2 ; //需要保存的图像类型
stParam.enPixelType = s1.enPixelType; //相机对应的像素格式
stParam.nBufferSize = pData; //存储节点的大小
stParam.nWidth = s1.nWidth ; //相机对应的宽
stParam.nHeight = s1.nHeight; //相机对应的高
stParam.nDataLen = s1.nFrameLen ;
stParam.pData = s;
stParam.nJpgQuality = 80;
stParam.pImageBuffer = ppData;
//console.dump( stParam)
nRet = dll.MV_CC_SaveImageEx2(pt.p,stParam)
string.save("\test.jpg", raw.tostring(ppData))
console.dump(nRet)
}
winform.button2.oncommand = function(id,event){
//console.dump(nRet, stIntValue.nCurValue)
}
winform.show();
win.loopMessage();
dll调用文件,只写了部分功能,打开摄像头和控制拍照
5 个回复 | 最后更新于 2022-06-28
此帖已被锁定,禁止回复

为啥提示加载不了dll,cannot load library,把dll保存在其他位置也不行
感谢分享,必须用海康摄像头吗?我有个usb的,明天测一下