/*图像抓取线程,主动调用SDK接口函数获取图像*/
UINT CBasicDlg::GrabThread()
{
tSdkFrameHead sFrameInfo;
BYTE* pRawBuffer;
// CameraSetTriggerMode(m_hCamera, 2);//设置相机硬件触发模式
while (!m_bExit)
{
if (CameraGetImageBuffer(m_hCamera, &sFrameInfo, &pRawBuffer, 1000) == CAMERA_STATUS_SUCCESS)
{
MyRawImage* pNewImage = (MyRawImage*)malloc(sizeof(MyRawImage) + sFrameInfo.uBytes);
if (pNewImage != NULL)
{
pNewImage->head = sFrameInfo;
memcpy(pNewImage->buffer, pRawBuffer, sFrameInfo.uBytes);
pNewImage->index = mySerialPort.cRecvednum;
}
CameraReleaseImageBuffer(m_hCamera, pRawBuffer);
if (pNewImage != NULL)
{
m_RawImageQL.Lock();
if (m_RawImageQ.size() < RAW_BUFFER_MAX_COUNT)
m_RawImageQ.push_back(pNewImage);
else
free(pNewImage);
m_RawImageQL.Unlock();
SetEvent(m_RawImageQE);
}
}
}
return 0;
}
UINT CBasicDlg::WorkThread()
{
MvTimer t;
Mat BIGframe0;
//const cv::Mat ComFrame = Mat::zeros(480 * 4, 640 * 18, CV_8UC1);
//const cv::Mat ColorComFrame = Mat::zeros(480 * 4, 640 * 18, CV_8UC3);
//cv::Mat MainWindows = Mat::zeros(300, 1800, CV_8UC1);
//cv::Mat ColorMainWindows = Mat::zeros(300, 1800, CV_8UC3);
const cv::Mat ComFrame(480 * 4, 640 * 18, CV_8UC1);
const cv::Mat ColorComFrame(480 * 4, 640 * 18, CV_8UC3);
cv::Mat MainWindows(300, 1800, CV_8UC1);
cv::Mat ColorMainWindows(300, 1800, CV_8UC3);
cv::Mat image1, image2;
bool start = false;
setMouseCallback("MainWindows", on_mouse, 0);//调用回调函数
while (!m_bExit)
{
if (WaitForSingleObject(m_RawImageQE, 200) != WAIT_OBJECT_0)
continue;
for (;;)
{
std::vector RawImageQ;
m_RawImageQL.Lock();
RawImageQ = m_RawImageQ;
m_RawImageQ.clear();
m_RawImageQL.Unlock();
if (RawImageQ.empty())
break;
for (size_t i = 0; i < RawImageQ.size(); ++i)
{
MyRawImage* pNewImage = (MyRawImage*)RawImageQ[i];
index = pNewImage->index;
if (index)
{
if (index == 1)
{
start = true;
}
if (start)
{
Mat image(pNewImage->head.iHeight, pNewImage->head.iWidth, CV_8UC1);
Mat resImage(600, 800, CV_8UC1);
memcpy(image.data, pNewImage->buffer, pNewImage->head.iHeight* pNewImage->head.iWidth);
cv::resize(image, resImage, cv::Size(800, 600), 0, 0, INTER_NEAREST);
flip(resImage, resImage, -1); //水平垂直翻转
//ImageStitch(index, image1, resImage, ComFrame);
//cv::resize(ComFrame, MainWindows, Size(1800, 300), 0, 0, INTER_NEAREST);
//imshow("MainWindows", MainWindows);
ImageStitch(index, image1, resImage, ColorComFrame);
cv::resize(ColorComFrame, ColorMainWindows, Size(1800, 300), 0, 0, INTER_NEAREST);
imshow("MainWindows", ColorMainWindows);
free(pNewImage); //测试用
////分辨率改变了,则刷新背景
//if (m_sFrInfo.iWidth != pNewImage->head.iWidth || m_sFrInfo.iHeight != pNewImage->head.iHeight)
//{
//m_sFrInfo.iWidth = pNewImage->head.iWidth;
//m_sFrInfo.iHeight = pNewImage->head.iHeight;
//InvalidateRect(NULL);
//}
m_iDispFrameNum++;
if (flag)
{
//dst = ComFrame(Rect((int)(min(cur_pt.x, pre_pt.x)*6.4), (int)(min(cur_pt.y, pre_pt.y)*6.4), width, height));
dst = ColorComFrame(Rect((int)(min(cur_pt.x, pre_pt.x)*6.4), (int)(min(cur_pt.y, pre_pt.y)*6.4), width, height));
imshow("view", dst);
}
}
}
}
}
}
return 0;
}