Files
newspark110/device/camera/cmvcamera.h
Chenwenxuan edac2715f0 init
2024-03-06 14:54:30 +08:00

191 lines
7.5 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/************************************************************************/
/* 以C++接口为基础,对常用函数进行二次封装,方便用户使用 */
/************************************************************************/
#ifndef _MV_CAMERA_H_
#define _MV_CAMERA_H_
#include "MvCameraControl.h"
#include <string.h>
#include <windows.h>
#include <QSettings>
#include <QString>
#include "opencv2/opencv.hpp"
using namespace cv;
#ifndef MV_NULL
#define MV_NULL 0
#endif
#define CAMERAFIND CMvCamera::instance()
class CMvCamera
{
public:
CMvCamera();
~CMvCamera();
static CMvCamera* instance();
// ch:获取SDK版本号 | en:Get SDK Version
static int GetSDKVersion();
// ch:枚举设备 | en:Enumerate Device
static int EnumDevices(unsigned int nTLayerType, MV_CC_DEVICE_INFO_LIST* pstDevList);
// ch:判断设备是否可达 | en:Is the device accessible
static bool IsDeviceAccessible(MV_CC_DEVICE_INFO* pstDevInfo, unsigned int nAccessMode);
// ch:打开设备 | en:Open Device
int Open(MV_CC_DEVICE_INFO* pstDeviceInfo);
// ch:关闭设备 | en:Close Device
int Close();
// ch:判断相机是否处于连接状态 | en:Is The Device Connected
bool IsDeviceConnected();
// ch:注册图像数据回调 | en:Register Image Data CallBack
int RegisterImageCallBack(void(__stdcall* cbOutput)(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser), void* pUser);
// ch:开启抓图 | en:Start Grabbing
int StartGrabbing();
// ch:停止抓图 | en:Stop Grabbing
int StopGrabbing();
// ch:主动获取一帧图像数据 | en:Get one frame initiatively
int GetImageBuffer(MV_FRAME_OUT* pFrame, int nMsec);
// ch:释放图像缓存 | en:Free image buffer
int FreeImageBuffer(MV_FRAME_OUT* pFrame);
// ch:显示一帧图像 | en:Display one frame image
int DisplayOneFrame(MV_DISPLAY_FRAME_INFO* pDisplayInfo);
// ch:设置SDK内部图像缓存节点个数 | en:Set the number of the internal image cache nodes in SDK
int SetImageNodeNum(unsigned int nNum);
// ch:获取设备信息 | en:Get device information
int GetDeviceInfo(MV_CC_DEVICE_INFO* pstDevInfo);
// ch:获取GEV相机的统计信息 | en:Get detect info of GEV camera
int GetGevAllMatchInfo(MV_MATCH_INFO_NET_DETECT* pMatchInfoNetDetect);
// ch:获取U3V相机的统计信息 | en:Get detect info of U3V camera
int GetU3VAllMatchInfo(MV_MATCH_INFO_USB_DETECT* pMatchInfoUSBDetect);
// ch:获取和设置Int型参数如 Width和Height详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
// en:Get Int type parameters, such as Width and Height, for details please refer to MvCameraNode.xlsx file under SDK installation directory
int GetIntValue(IN const char* strKey, OUT MVCC_INTVALUE_EX *pIntValue);
int SetIntValue(IN const char* strKey, IN int64_t nValue);
// ch:获取和设置Enum型参数如 PixelFormat详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
// en:Get Enum type parameters, such as PixelFormat, for details please refer to MvCameraNode.xlsx file under SDK installation directory
int GetEnumValue(IN const char* strKey, OUT MVCC_ENUMVALUE *pEnumValue);
int SetEnumValue(IN const char* strKey, IN unsigned int nValue);
int SetEnumValueByString(IN const char* strKey, IN const char* sValue);
int GetEnumEntrySymbolic(IN const char* strKey, IN MVCC_ENUMENTRY* pstEnumEntry);
// ch:获取和设置Float型参数如 ExposureTime和Gain详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
// en:Get Float type parameters, such as ExposureTime and Gain, for details please refer to MvCameraNode.xlsx file under SDK installation directory
int GetFloatValue(IN const char* strKey, OUT MVCC_FLOATVALUE *pFloatValue);
int SetFloatValue(IN const char* strKey, IN float fValue);
// ch:获取和设置Bool型参数如 ReverseX详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
// en:Get Bool type parameters, such as ReverseX, for details please refer to MvCameraNode.xlsx file under SDK installation directory
int GetBoolValue(IN const char* strKey, OUT bool *pbValue);
int SetBoolValue(IN const char* strKey, IN bool bValue);
// ch:获取和设置String型参数如 DeviceUserID详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件UserSetSave
// en:Get String type parameters, such as DeviceUserID, for details please refer to MvCameraNode.xlsx file under SDK installation directory
int GetStringValue(IN const char* strKey, MVCC_STRINGVALUE *pStringValue);
int SetStringValue(IN const char* strKey, IN const char * strValue);
// ch:执行一次Command型命令如 UserSetSave详细内容参考SDK安装目录下的 MvCameraNode.xlsx 文件
// en:Execute Command once, such as UserSetSave, for details please refer to MvCameraNode.xlsx file under SDK installation directory
int CommandExecute(IN const char* strKey);
// ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)
int GetOptimalPacketSize(unsigned int* pOptimalPacketSize);
// ch:注册消息异常回调 | en:Register Message Exception CallBack
int RegisterExceptionCallBack(void(__stdcall* cbException)(unsigned int nMsgType, void* pUser), void* pUser);
// ch:注册单个事件回调 | en:Register Event CallBack
int RegisterEventCallBack(const char* pEventName, void(__stdcall* cbEvent)(MV_EVENT_OUT_INFO * pEventInfo, void* pUser), void* pUser);
// ch:强制IP | en:Force IP
int ForceIp(unsigned int nIP, unsigned int nSubNetMask, unsigned int nDefaultGateWay);
// ch:配置IP方式 | en:IP configuration method
int SetIpConfig(unsigned int nType);
// ch:设置网络传输模式 | en:Set Net Transfer Mode
int SetNetTransMode(unsigned int nType);
// ch:像素格式转换 | en:Pixel format conversion
int ConvertPixelType(MV_CC_PIXEL_CONVERT_PARAM* pstCvtParam);
// ch:保存图片 | en:save image
int SaveImage(MV_SAVE_IMAGE_PARAM_EX* pstParam);
// ch:保存图片为文件 | en:Save the image as a file
int SaveImageToFile(MV_SAVE_IMG_TO_FILE_PARAM* pstParam);
// ch:绘制圆形辅助线 | en:Draw circle auxiliary line
int DrawCircle(MVCC_CIRCLE_INFO* pCircleInfo);
// ch:绘制线形辅助线 | en:Draw lines auxiliary line
int DrawLines(MVCC_LINES_INFO* pLinesInfo);
// 读取buffer
int ReadBuffer(Mat &image);
// 读取buffer
int GetImage(Mat &image,bool FindFlag);
int setPoints(std::vector<cv::Point> points, cv::Mat &image);
std::vector<cv::Point> getPoints(cv::Mat &image, int value);
//bool SortByX(Point &v1, Point &v2);
//bool SortByY(Point &v1, Point &v2);
int GetLineSlope(Mat &src,bool &result,double *slope);
int GetGap(Mat &src,bool &result,int *xPos);
int getCameraPara(QString DevName);
int ClearImageBuffer();
int GetCrossPoint(Mat& src, bool left,int * top);
int getLinePoints_bottom(Mat& img);
int calc_arc_bypoints3(double* points0, double* points1, double* points2, double* center, double* radius);
std::vector<cv::Point> getLinePoints(Mat img);
private:
void* m_hDevHandle;
unsigned int m_nBufSizeForSaveImage;
static CMvCamera* uniqueInstance;
CRITICAL_SECTION mCsRead;
//参数7取点间隔
//参数6轮廓点数量
//参数5Y方向差值
//参数4连续合格点数量排除干扰
//参数3Y方向偏移值
//参数2Y方向起始值
//参数1阈值
public:
int ParaThreshold;
int YOffsetPos;
int ContinuePointSum;
int YPointValueDiff;
int YPointValueDiff_6;
int ContoursPointSum;
int LinePointCount;
int SumValueThresh;
int StepOfFalse;
int StepOfTrue;
int ExposureTimeFindEdge;
int ExposureTime;
};
#endif//_MV_CAMERA_H_