|
@@ -23,10 +23,14 @@ using boost::asio::ip::tcp;
|
|
|
|
|
|
|
|
namespace
|
|
namespace
|
|
|
{
|
|
{
|
|
|
- const int kVideoPreviewWidth = 600;
|
|
|
|
|
- const int kVideoPreviewHeight = 450;
|
|
|
|
|
- const int kVideoMinWidth = 400;
|
|
|
|
|
- const int kVideoMinHeight = 300;
|
|
|
|
|
|
|
+ //摄像头拍摄的图片的原始尺寸,本系统里面默认为800*600
|
|
|
|
|
+ const int kVideoWidth = 800;
|
|
|
|
|
+ const int kVideoHeight = 600;
|
|
|
|
|
+
|
|
|
|
|
+ //红色边框的最小尺寸
|
|
|
|
|
+ const int kVideoBorderMinWidth = 400;
|
|
|
|
|
+ const int kVideoBorderMinHeight = 300;
|
|
|
|
|
+
|
|
|
const int kVideoGripSize = 8;
|
|
const int kVideoGripSize = 8;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -3459,6 +3463,9 @@ void CSettingPageUI::SwitchSettingPage(std::wstring page_name)
|
|
|
|
|
|
|
|
void CSettingPageUI::HandleUpdateVideo()
|
|
void CSettingPageUI::HandleUpdateVideo()
|
|
|
{
|
|
{
|
|
|
|
|
+ //在刚启动摄像头线程的时候,读取一次数据库中的裁剪框坐标就行了,拖动过程中只修改m_videoBorderRect变量,鼠标释放的时候再保存到数据库中
|
|
|
|
|
+ LoadVideoBorderRect();
|
|
|
|
|
+
|
|
|
while (m_is_show_video_capture == true)
|
|
while (m_is_show_video_capture == true)
|
|
|
{
|
|
{
|
|
|
if (m_pMainWnd->GetCurPageName() != CMainWnd::SETTING)
|
|
if (m_pMainWnd->GetCurPageName() != CMainWnd::SETTING)
|
|
@@ -3482,8 +3489,13 @@ void CSettingPageUI::HandleUpdateVideo()
|
|
|
cvtColor(img, img, cv::COLOR_GRAY2BGR);
|
|
cvtColor(img, img, cv::COLOR_GRAY2BGR);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //缩放尺寸,适合在界面上展示,过大过小都不好看,这个尺寸是根据界面上image控件的大小来定的,可以根据实际情况调整
|
|
|
|
|
- cv::resize(img, img, cv::Size(kVideoPreviewWidth, kVideoPreviewHeight), 0, 0, cv::INTER_LINEAR);
|
|
|
|
|
|
|
+ //缩放尺寸,适合在界面上展示,过大过小都不好看,这个尺寸是根据界面上image控件的大小来定的,可以根据实际情况调整(摄像头拍摄出来的,默认为800*600)
|
|
|
|
|
+ CControlUI* pImage = static_cast<CControlUI*>(this->FindSubControl(_T("image_video")));
|
|
|
|
|
+ RECT imageRect = pImage->GetPos();
|
|
|
|
|
+ int imageWidth = imageRect.right - imageRect.left;
|
|
|
|
|
+ int imageHeight = imageRect.bottom - imageRect.top;
|
|
|
|
|
+
|
|
|
|
|
+ cv::resize(img, img, cv::Size(imageWidth, imageHeight), 0, 0, cv::INTER_LINEAR);
|
|
|
|
|
|
|
|
// 创建或更新位图
|
|
// 创建或更新位图
|
|
|
HDC hDC = GetDC(NULL);
|
|
HDC hDC = GetDC(NULL);
|
|
@@ -3515,8 +3527,6 @@ void CSettingPageUI::HandleUpdateVideo()
|
|
|
|
|
|
|
|
void CSettingPageUI::UpdateVideoShow()
|
|
void CSettingPageUI::UpdateVideoShow()
|
|
|
{
|
|
{
|
|
|
- LoadVideoBorderRect();
|
|
|
|
|
-
|
|
|
|
|
HDC hDC = m_pManager->GetPaintDC();
|
|
HDC hDC = m_pManager->GetPaintDC();
|
|
|
if (!hDC || !m_hBitmap)
|
|
if (!hDC || !m_hBitmap)
|
|
|
{
|
|
{
|
|
@@ -3633,18 +3643,18 @@ void CSettingPageUI::LoadVideoBorderRect()
|
|
|
|
|
|
|
|
int x = readInt(CSetting::GetInstance()->GetParam("setting_ai_video_rect_x"), 0);
|
|
int x = readInt(CSetting::GetInstance()->GetParam("setting_ai_video_rect_x"), 0);
|
|
|
int y = readInt(CSetting::GetInstance()->GetParam("setting_ai_video_rect_y"), 0);
|
|
int y = readInt(CSetting::GetInstance()->GetParam("setting_ai_video_rect_y"), 0);
|
|
|
- int w = readInt(CSetting::GetInstance()->GetParam("setting_ai_video_rect_w"), kVideoPreviewWidth);
|
|
|
|
|
- int h = readInt(CSetting::GetInstance()->GetParam("setting_ai_video_rect_h"), kVideoPreviewHeight);
|
|
|
|
|
|
|
+ int w = readInt(CSetting::GetInstance()->GetParam("setting_ai_video_rect_w"), kVideoWidth);
|
|
|
|
|
+ int h = readInt(CSetting::GetInstance()->GetParam("setting_ai_video_rect_h"), kVideoHeight);
|
|
|
|
|
|
|
|
- if (w < kVideoMinWidth) w = kVideoMinWidth;
|
|
|
|
|
- if (h < kVideoMinHeight) h = kVideoMinHeight;
|
|
|
|
|
- if (w > kVideoPreviewWidth) w = kVideoPreviewWidth;
|
|
|
|
|
- if (h > kVideoPreviewHeight) h = kVideoPreviewHeight;
|
|
|
|
|
|
|
+ if (w < kVideoBorderMinWidth) w = kVideoBorderMinWidth;
|
|
|
|
|
+ if (h < kVideoBorderMinHeight) h = kVideoBorderMinHeight;
|
|
|
|
|
+ if (w > kVideoWidth) w = kVideoWidth;
|
|
|
|
|
+ if (h > kVideoHeight) h = kVideoHeight;
|
|
|
|
|
|
|
|
if (x < 0) x = 0;
|
|
if (x < 0) x = 0;
|
|
|
if (y < 0) y = 0;
|
|
if (y < 0) y = 0;
|
|
|
- if (x + w > kVideoPreviewWidth) x = kVideoPreviewWidth - w;
|
|
|
|
|
- if (y + h > kVideoPreviewHeight) y = kVideoPreviewHeight - h;
|
|
|
|
|
|
|
+ if (x + w > kVideoWidth) x = kVideoWidth - w;
|
|
|
|
|
+ if (y + h > kVideoHeight) y = kVideoHeight - h;
|
|
|
|
|
|
|
|
m_videoBorderRect.left = x;
|
|
m_videoBorderRect.left = x;
|
|
|
m_videoBorderRect.top = y;
|
|
m_videoBorderRect.top = y;
|
|
@@ -3691,10 +3701,10 @@ RECT CSettingPageUI::GetVideoBorderDisplayRect(const RECT& imageRect)
|
|
|
return rc;
|
|
return rc;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- rc.left = imageRect.left + MulDiv(m_videoBorderRect.left, imageWidth, kVideoPreviewWidth);
|
|
|
|
|
- rc.top = imageRect.top + MulDiv(m_videoBorderRect.top, imageHeight, kVideoPreviewHeight);
|
|
|
|
|
- rc.right = imageRect.left + MulDiv(m_videoBorderRect.right, imageWidth, kVideoPreviewWidth);
|
|
|
|
|
- rc.bottom = imageRect.top + MulDiv(m_videoBorderRect.bottom, imageHeight, kVideoPreviewHeight);
|
|
|
|
|
|
|
+ rc.left = imageRect.left + MulDiv(m_videoBorderRect.left, imageWidth, kVideoWidth);
|
|
|
|
|
+ rc.top = imageRect.top + MulDiv(m_videoBorderRect.top, imageHeight, kVideoHeight);
|
|
|
|
|
+ rc.right = imageRect.left + MulDiv(m_videoBorderRect.right, imageWidth, kVideoWidth);
|
|
|
|
|
+ rc.bottom = imageRect.top + MulDiv(m_videoBorderRect.bottom, imageHeight, kVideoHeight);
|
|
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
|
}
|
|
}
|
|
@@ -3737,7 +3747,7 @@ bool CSettingPageUI::HandleVideoBorderMouseMessage(UINT uMsg, WPARAM wParam, LPA
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- LoadVideoBorderRect();
|
|
|
|
|
|
|
+ //LoadVideoBorderRect();
|
|
|
|
|
|
|
|
RECT imageRect = GetVideoImageRect();
|
|
RECT imageRect = GetVideoImageRect();
|
|
|
int imageWidth = imageRect.right - imageRect.left;
|
|
int imageWidth = imageRect.right - imageRect.left;
|
|
@@ -3747,6 +3757,7 @@ bool CSettingPageUI::HandleVideoBorderMouseMessage(UINT uMsg, WPARAM wParam, LPA
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //计算红色边框在界面上的显示位置
|
|
|
RECT borderRect = GetVideoBorderDisplayRect(imageRect);
|
|
RECT borderRect = GetVideoBorderDisplayRect(imageRect);
|
|
|
|
|
|
|
|
auto setCursorByHit = [](int hitType) -> bool
|
|
auto setCursorByHit = [](int hitType) -> bool
|
|
@@ -3828,36 +3839,36 @@ bool CSettingPageUI::HandleVideoBorderMouseMessage(UINT uMsg, WPARAM wParam, LPA
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- int dx = MulDiv(pt.x - m_videoBorderDragStartPt.x, kVideoPreviewWidth, imageWidth);
|
|
|
|
|
- int dy = MulDiv(pt.y - m_videoBorderDragStartPt.y, kVideoPreviewHeight, imageHeight);
|
|
|
|
|
|
|
+ int dx = MulDiv(pt.x - m_videoBorderDragStartPt.x, kVideoWidth, imageWidth);
|
|
|
|
|
+ int dy = MulDiv(pt.y - m_videoBorderDragStartPt.y, kVideoHeight, imageHeight);
|
|
|
|
|
|
|
|
RECT newRect = m_videoBorderDragStartRect;
|
|
RECT newRect = m_videoBorderDragStartRect;
|
|
|
|
|
|
|
|
if (m_videoBorderHitType == HTLEFT || m_videoBorderHitType == HTTOPLEFT || m_videoBorderHitType == HTBOTTOMLEFT)
|
|
if (m_videoBorderHitType == HTLEFT || m_videoBorderHitType == HTTOPLEFT || m_videoBorderHitType == HTBOTTOMLEFT)
|
|
|
{
|
|
{
|
|
|
- int maxLeft = static_cast<int>(m_videoBorderDragStartRect.right) - kVideoMinWidth;
|
|
|
|
|
|
|
+ int maxLeft = static_cast<int>(m_videoBorderDragStartRect.right) - kVideoBorderMinWidth;
|
|
|
int left = std::max(0, std::min(static_cast<int>(m_videoBorderDragStartRect.left) + dx, maxLeft));
|
|
int left = std::max(0, std::min(static_cast<int>(m_videoBorderDragStartRect.left) + dx, maxLeft));
|
|
|
newRect.left = static_cast<LONG>(left);
|
|
newRect.left = static_cast<LONG>(left);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (m_videoBorderHitType == HTRIGHT || m_videoBorderHitType == HTTOPRIGHT || m_videoBorderHitType == HTBOTTOMRIGHT)
|
|
if (m_videoBorderHitType == HTRIGHT || m_videoBorderHitType == HTTOPRIGHT || m_videoBorderHitType == HTBOTTOMRIGHT)
|
|
|
{
|
|
{
|
|
|
- int minRight = static_cast<int>(m_videoBorderDragStartRect.left) + kVideoMinWidth;
|
|
|
|
|
- int right = std::max(minRight, std::min(static_cast<int>(m_videoBorderDragStartRect.right) + dx, kVideoPreviewWidth));
|
|
|
|
|
|
|
+ int minRight = static_cast<int>(m_videoBorderDragStartRect.left) + kVideoBorderMinWidth;
|
|
|
|
|
+ int right = std::max(minRight, std::min(static_cast<int>(m_videoBorderDragStartRect.right) + dx, kVideoWidth));
|
|
|
newRect.right = static_cast<LONG>(right);
|
|
newRect.right = static_cast<LONG>(right);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (m_videoBorderHitType == HTTOP || m_videoBorderHitType == HTTOPLEFT || m_videoBorderHitType == HTTOPRIGHT)
|
|
if (m_videoBorderHitType == HTTOP || m_videoBorderHitType == HTTOPLEFT || m_videoBorderHitType == HTTOPRIGHT)
|
|
|
{
|
|
{
|
|
|
- int maxTop = static_cast<int>(m_videoBorderDragStartRect.bottom) - kVideoMinHeight;
|
|
|
|
|
|
|
+ int maxTop = static_cast<int>(m_videoBorderDragStartRect.bottom) - kVideoBorderMinHeight;
|
|
|
int top = std::max(0, std::min(static_cast<int>(m_videoBorderDragStartRect.top) + dy, maxTop));
|
|
int top = std::max(0, std::min(static_cast<int>(m_videoBorderDragStartRect.top) + dy, maxTop));
|
|
|
newRect.top = static_cast<LONG>(top);
|
|
newRect.top = static_cast<LONG>(top);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (m_videoBorderHitType == HTBOTTOM || m_videoBorderHitType == HTBOTTOMLEFT || m_videoBorderHitType == HTBOTTOMRIGHT)
|
|
if (m_videoBorderHitType == HTBOTTOM || m_videoBorderHitType == HTBOTTOMLEFT || m_videoBorderHitType == HTBOTTOMRIGHT)
|
|
|
{
|
|
{
|
|
|
- int minBottom = static_cast<int>(m_videoBorderDragStartRect.top) + kVideoMinHeight;
|
|
|
|
|
- int bottom = std::max(minBottom, std::min(static_cast<int>(m_videoBorderDragStartRect.bottom) + dy, kVideoPreviewHeight));
|
|
|
|
|
|
|
+ int minBottom = static_cast<int>(m_videoBorderDragStartRect.top) + kVideoBorderMinHeight;
|
|
|
|
|
+ int bottom = std::max(minBottom, std::min(static_cast<int>(m_videoBorderDragStartRect.bottom) + dy, kVideoHeight));
|
|
|
newRect.bottom = static_cast<LONG>(bottom);
|
|
newRect.bottom = static_cast<LONG>(bottom);
|
|
|
}
|
|
}
|
|
|
|
|
|