init
This commit is contained in:
1351
device/camera/cmvcamera.cpp
Normal file
1351
device/camera/cmvcamera.cpp
Normal file
File diff suppressed because it is too large
Load Diff
190
device/camera/cmvcamera.h
Normal file
190
device/camera/cmvcamera.h
Normal file
@@ -0,0 +1,190 @@
|
||||
/************************************************************************/
|
||||
/* <20><>C++<2B>ӿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD><D4B3>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>η<EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ʹ<EFBFBD><CAB9> */
|
||||
/************************************************************************/
|
||||
|
||||
#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:<3A><>ȡSDK<44>汾<EFBFBD><E6B1BE> | en:Get SDK Version
|
||||
static int GetSDKVersion();
|
||||
|
||||
// ch:ö<><C3B6><EFBFBD>豸 | en:Enumerate Device
|
||||
static int EnumDevices(unsigned int nTLayerType, MV_CC_DEVICE_INFO_LIST* pstDevList);
|
||||
|
||||
// ch:<3A>ж<EFBFBD><D0B6>豸<EFBFBD>Ƿ<EFBFBD><C7B7>ɴ<EFBFBD> | en:Is the device accessible
|
||||
static bool IsDeviceAccessible(MV_CC_DEVICE_INFO* pstDevInfo, unsigned int nAccessMode);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD><EFBFBD>豸 | en:Open Device
|
||||
int Open(MV_CC_DEVICE_INFO* pstDeviceInfo);
|
||||
|
||||
// ch:<3A>ر<EFBFBD><D8B1>豸 | en:Close Device
|
||||
int Close();
|
||||
|
||||
// ch:<3A>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬ | en:Is The Device Connected
|
||||
bool IsDeviceConnected();
|
||||
|
||||
// ch:ע<><D7A2>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>ݻص<DDBB> | en:Register Image Data CallBack
|
||||
int RegisterImageCallBack(void(__stdcall* cbOutput)(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser), void* pUser);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>ץͼ | en:Start Grabbing
|
||||
int StartGrabbing();
|
||||
|
||||
// ch:ֹͣץͼ | en:Stop Grabbing
|
||||
int StopGrabbing();
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡһ֡ͼ<D6A1><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | en:Get one frame initiatively
|
||||
int GetImageBuffer(MV_FRAME_OUT* pFrame, int nMsec);
|
||||
|
||||
// ch:<3A>ͷ<EFBFBD>ͼ<EFBFBD><EFBFBD> | en:Free image buffer
|
||||
int FreeImageBuffer(MV_FRAME_OUT* pFrame);
|
||||
|
||||
// ch:<3A><>ʾһ֡ͼ<D6A1><CDBC> | en:Display one frame image
|
||||
int DisplayOneFrame(MV_DISPLAY_FRAME_INFO* pDisplayInfo);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>SDK<44>ڲ<EFBFBD>ͼ<EFBFBD><EFBFBD><F1BBBAB4>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD> | en:Set the number of the internal image cache nodes in SDK
|
||||
int SetImageNodeNum(unsigned int nNum);
|
||||
|
||||
// ch:<3A><>ȡ<EFBFBD>豸<EFBFBD><E8B1B8>Ϣ | en:Get device information
|
||||
int GetDeviceInfo(MV_CC_DEVICE_INFO* pstDevInfo);
|
||||
|
||||
// ch:<3A><>ȡGEV<45><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ϣ | en:Get detect info of GEV camera
|
||||
int GetGevAllMatchInfo(MV_MATCH_INFO_NET_DETECT* pMatchInfoNetDetect);
|
||||
|
||||
// ch:<3A><>ȡU3V<33><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ϣ | en:Get detect info of U3V camera
|
||||
int GetU3VAllMatchInfo(MV_MATCH_INFO_USB_DETECT* pMatchInfoUSBDetect);
|
||||
|
||||
// ch:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Int<6E>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Width<74><68>Height<68><74><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>
|
||||
// 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:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Enum<75>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PixelFormat<61><74><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>
|
||||
// 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:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Float<61>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ExposureTime<6D><65>Gain<69><6E><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>
|
||||
// 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:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Bool<6F>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ReverseX<65><58><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>
|
||||
// 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:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>String<6E>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> DeviceUserID<49><44><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>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:ִ<><D6B4>һ<EFBFBD><D2BB>Command<6E><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEA3AC> UserSetSave<76><65><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD>ݲο<DDB2>SDK<44><4B>װĿ¼<C4BF>µ<EFBFBD> MvCameraNode.xlsx <20>ļ<EFBFBD>
|
||||
// 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:̽<><CCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѱ<EFBFBD><D1B0><EFBFBD>С(ֻ<><D6BB>GigE<67><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч) | en:Detection network optimal package size(It only works for the GigE camera)
|
||||
int GetOptimalPacketSize(unsigned int* pOptimalPacketSize);
|
||||
|
||||
// ch:ע<><D7A2><EFBFBD><EFBFBD>Ϣ<EFBFBD>쳣<EFBFBD>ص<EFBFBD> | en:Register Message Exception CallBack
|
||||
int RegisterExceptionCallBack(void(__stdcall* cbException)(unsigned int nMsgType, void* pUser), void* pUser);
|
||||
|
||||
// ch:ע<>ᵥ<EFBFBD><E1B5A5><EFBFBD>¼<EFBFBD><C2BC>ص<EFBFBD> | en:Register Event CallBack
|
||||
int RegisterEventCallBack(const char* pEventName, void(__stdcall* cbEvent)(MV_EVENT_OUT_INFO * pEventInfo, void* pUser), void* pUser);
|
||||
|
||||
// ch:ǿ<><C7BF>IP | en:Force IP
|
||||
int ForceIp(unsigned int nIP, unsigned int nSubNetMask, unsigned int nDefaultGateWay);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>IP<49><50>ʽ | en:IP configuration method
|
||||
int SetIpConfig(unsigned int nType);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>紫<EFBFBD><E7B4AB>ģʽ | en:Set Net Transfer Mode
|
||||
int SetNetTransMode(unsigned int nType);
|
||||
|
||||
// ch:<3A><><EFBFBD>ظ<EFBFBD>ʽת<CABD><D7AA> | en:Pixel format conversion
|
||||
int ConvertPixelType(MV_CC_PIXEL_CONVERT_PARAM* pstCvtParam);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>ͼƬ | en:save image
|
||||
int SaveImage(MV_SAVE_IMAGE_PARAM_EX* pstParam);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>ͼƬΪ<C6AC>ļ<EFBFBD> | en:Save the image as a file
|
||||
int SaveImageToFile(MV_SAVE_IMG_TO_FILE_PARAM* pstParam);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD>Բ<EFBFBD>θ<EFBFBD><CEB8><EFBFBD><EFBFBD><EFBFBD> | en:Draw circle auxiliary line
|
||||
int DrawCircle(MVCC_CIRCLE_INFO* pCircleInfo);
|
||||
|
||||
// ch:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>θ<EFBFBD><CEB8><EFBFBD><EFBFBD><EFBFBD> | en:Draw lines auxiliary line
|
||||
int DrawLines(MVCC_LINES_INFO* pLinesInfo);
|
||||
|
||||
// <20><>ȡbuffer
|
||||
int ReadBuffer(Mat &image);
|
||||
|
||||
// <20><>ȡ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;
|
||||
//<2F><><EFBFBD><EFBFBD>7<EFBFBD><37>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD>6<EFBFBD><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD>5<EFBFBD><35>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
//<2F><><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ų<EFBFBD><C5B3><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD>3<EFBFBD><33>Y<EFBFBD><59><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>ֵ
|
||||
//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼֵ
|
||||
//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>ֵ
|
||||
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_
|
||||
85
device/camera/readcameraimagethread.cpp
Normal file
85
device/camera/readcameraimagethread.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "readcameraimagethread.h"
|
||||
|
||||
ReadCameraImageThread::ReadCameraImageThread(QObject *parent)
|
||||
:QThread(parent)
|
||||
{
|
||||
myImage = new QImage();
|
||||
}
|
||||
|
||||
ReadCameraImageThread::~ReadCameraImageThread()
|
||||
{
|
||||
delete myImage;
|
||||
if(NULL == cameraPtr)
|
||||
{
|
||||
delete cameraPtr;
|
||||
}
|
||||
if(NULL == imagePtr)
|
||||
{
|
||||
delete imagePtr;
|
||||
}
|
||||
}
|
||||
|
||||
void ReadCameraImageThread::run()
|
||||
{
|
||||
if(NULL==cameraPtr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(NULL==imagePtr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while(!isInterruptionRequested())
|
||||
{
|
||||
// qDebug()<<"SoftTrigger:"<<cameraPtr->CommandExecute("TriggerSoftware");
|
||||
// qDebug()<<"ReadBuffer:"<<cameraPtr->ReadBuffer(*imagePtr);
|
||||
//cameraPtr->CommandExecute("TriggerSoftware");
|
||||
//cameraPtr->ReadBuffer(*imagePtr);
|
||||
cameraPtr->GetImage(*imagePtr,false);
|
||||
if(isEnableCrossHairLine)
|
||||
{
|
||||
drawCrossHairLine();
|
||||
}
|
||||
|
||||
if(imagePtr->channels()>1)
|
||||
{
|
||||
*myImage = QImage((const unsigned char*)(imagePtr->data),imagePtr->cols,imagePtr->rows,QImage::Format_RGB888);
|
||||
}
|
||||
else
|
||||
{
|
||||
*myImage = QImage((const unsigned char*)(imagePtr->data),imagePtr->cols,imagePtr->rows,QImage::Format_Indexed8);
|
||||
}
|
||||
|
||||
emit messageImageSGL(*myImage);
|
||||
msleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadCameraImageThread::getCameraPtr(CMvCamera *camera)
|
||||
{
|
||||
cameraPtr = camera;
|
||||
}
|
||||
|
||||
void ReadCameraImageThread::getImagePtr(cv::Mat *image)
|
||||
{
|
||||
imagePtr = image;
|
||||
}
|
||||
|
||||
void ReadCameraImageThread::drawCrossHairLine(Scalar lineColor,int lineWidth)
|
||||
{
|
||||
int heigh = imagePtr->rows;
|
||||
int width = imagePtr->cols;
|
||||
// 水平线
|
||||
Point startPH(0,int(heigh/2)),endPH(int(width),int(heigh/2));
|
||||
line(*imagePtr,startPH,endPH,lineColor,lineWidth);
|
||||
// 垂直线
|
||||
Point startPV(int(width/2),0),endPV(int(width/2),int(heigh));
|
||||
line(*imagePtr,startPV,endPV,lineColor,lineWidth);
|
||||
}
|
||||
|
||||
void ReadCameraImageThread::setEnableCrossHairLine(bool value )
|
||||
{
|
||||
isEnableCrossHairLine = value;
|
||||
|
||||
}
|
||||
38
device/camera/readcameraimagethread.h
Normal file
38
device/camera/readcameraimagethread.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef READCAMERAIMAGETHREAD_H
|
||||
#define READCAMERAIMAGETHREAD_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QImage>
|
||||
#include <QDebug>
|
||||
#include "cmvcamera.h"
|
||||
|
||||
class ReadCameraImageThread:public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ReadCameraImageThread(QObject *parent = nullptr);
|
||||
~ReadCameraImageThread();
|
||||
|
||||
void run();
|
||||
void getCameraPtr(CMvCamera *camera);
|
||||
void getImagePtr(cv::Mat *image);
|
||||
void setEnableCrossHairLine(bool value = true);
|
||||
|
||||
|
||||
signals:
|
||||
void messageSGL();
|
||||
void messageImageSGL(QImage myImage);
|
||||
private:
|
||||
void drawCrossHairLine(Scalar lineColor = Scalar(255,0,0),int lineWidth = 2);
|
||||
|
||||
private:
|
||||
CMvCamera *cameraPtr = nullptr;
|
||||
cv::Mat *imagePtr = nullptr;
|
||||
QImage *myImage = nullptr;
|
||||
bool isEnableCrossHairLine{true};
|
||||
|
||||
};
|
||||
|
||||
#endif // RAADCAMRAIMAGETHREAD_H
|
||||
Reference in New Issue
Block a user