⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageobjectdlg.cpp.bak

📁 实时视频捕获
💻 BAK
📖 第 1 页 / 共 4 页
字号:
	//设置视频属性:亮度、对比度、色度、饱和度
	DSStream_SetVideoPropertyValue(m_CardID, VideoProperty_Brightness, SaveData.brightness);
	DSStream_SetVideoPropertyValue(m_CardID, VideoProperty_Contrast, SaveData.contrast);
	//设置视频格式:视频格式、宽、高
	DSStream_GetVideoInfo(m_CardID, &vsi, PREVIEW);
	vsi.subtype = VideoSubType_YUY2;
	vsi.bmiHeader.biWidth = IMAGE_WIDTH;
	vsi.bmiHeader.biHeight= IMAGE_HEIGHT;
	DSStream_DisconnectPin(m_CardID, PREVIEW);
	DSStream_SetVideoInfo(m_CardID, vsi, PREVIEW);
	DSStream_ConnectPin(m_CardID, PREVIEW);

}
*/
//保存卡的当前属性,以备下次连接时重新设回

void CImageObjectDlg::OnBnClickedBtnSet()
{
	// TODO: Add your control notification handler code here
/*
	CFile fileDeliver;
				int k;
				CString str;
				if(fileDeliver.Open(_T("C:\\sendcount.txt"),CFile::modeReadWrite |CFile::osWriteThrough ,NULL))
				{
					char buffer[20];
					int readnum=fileDeliver.Read(buffer,20);
					if(readnum)
					{
						k=atoi(buffer);
						k=1000+k;
					}else
					{
						k=100;
					}
					fileDeliver.SeekToBegin();
					_itoa(k,buffer,10);
					str=buffer;
					fileDeliver.Write(buffer,20);
					fileDeliver.Close();
				}
*/
	if(m_SetEnable)
	{
		m_SetEnable=FALSE;
		this->m_bntSetDetect.SetWindowTextW(_T("检测设定"));
		this->m_SelectDetectRegion.EnableWindow(FALSE);
		this->m_SetDetectNum.EnableWindow(FALSE);
		this->m_SetDetectRegionHeight.EnableWindow(FALSE);
		this->m_SetDetectRegionWidth.EnableWindow(FALSE);
		this->m_SetDetectThreshold.EnableWindow(FALSE);
		this->m_ImageContrastSlider.EnableWindow(FALSE);
		this->m_ImageLightSlider.EnableWindow(FALSE);
		this->m_SelectDetectRegion.ShowWindow(SW_HIDE );
		this->m_SetDetectNum.ShowWindow(SW_HIDE );
		this->m_SetDetectRegionHeight.ShowWindow(SW_HIDE );
		this->m_SetDetectRegionWidth.ShowWindow(SW_HIDE );
		this->m_SetDetectThreshold.ShowWindow(SW_HIDE );
		this->m_ImageContrastSlider.ShowWindow(SW_HIDE );
		this->m_ImageLightSlider.ShowWindow(SW_HIDE );
		this->SaveParameter();
	}else
	{
		m_SetEnable=TRUE;
		this->m_bntSetDetect.SetWindowTextW(_T("设定完成"));
		this->m_SelectDetectRegion.ShowWindow(SW_SHOW    );
		this->m_SetDetectNum.ShowWindow(SW_SHOW    );
		this->m_SetDetectRegionHeight.ShowWindow(SW_SHOW    );
		this->m_SetDetectRegionWidth.ShowWindow(SW_SHOW    );
		this->m_SetDetectThreshold.ShowWindow(SW_SHOW    );
		this->m_ImageContrastSlider.ShowWindow(SW_SHOW    );
		this->m_ImageLightSlider.ShowWindow(SW_SHOW    );
		this->m_SelectDetectRegion.EnableWindow(TRUE);
		this->m_SetDetectNum.EnableWindow(TRUE);
		this->m_SetDetectRegionHeight.EnableWindow(TRUE);
		this->m_SetDetectRegionWidth.EnableWindow(TRUE);
		this->m_SetDetectThreshold.EnableWindow(TRUE);
		this->m_ImageContrastSlider.EnableWindow(TRUE);
		this->m_ImageLightSlider.EnableWindow(TRUE);
		m_SelectDetectRegion.SetCurSel(m_iCurrentDetectRegionID);
	}
}

void CImageObjectDlg::OnEnChangeRe2RegionCountSet()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here
	int end=m_SetDetectNum.GetTextLength();
	CString str;
	m_SetDetectNum.GetTextRange(0,end,str);
	int k=_ttoi(str);
	for(int i=0;i<k;i++)
	{
		str.Format(_T("%d%s"),i+1,_T("号检测区域"));
		this->m_SelectDetectRegion.InsertString(i,(LPCTSTR)str);
	}
	
}

void CImageObjectDlg::OnEnKillfocusRe2RegionCountSet()
{
	// TODO: Add your control notification handler code here
	int end=m_SetDetectNum.GetTextLength();
	CString str;
	m_SetDetectNum.GetTextRange(0,end,str);
	int k=_ttoi(str);
	m_SelectDetectRegion.ResetContent();
	for(int i=0;i<k;i++)
	{
		str.Format(_T("%d%s"),i,_T("号检测区域"));
		this->m_SelectDetectRegion.InsertString(i,(LPCTSTR)str);
		m_SelectDetectRegion.SetCurSel(m_iCurrentDetectRegionID);
		
	}
	m_SysSetPara.detect_num=k;
	Invalidate();
}

void CImageObjectDlg::OnCbnSelchangeComboSelectRegion()
{
	// TODO: Add your control notification handler code here
	int index=m_SelectDetectRegion.GetCurSel();
	CString str;
	str.Format(_T("%d"),m_SysSetPara.dtr[index].region.Height());
	this->m_SetDetectRegionHeight.SetWindowTextW(str);
	str.Format(_T("%d"),m_SysSetPara.dtr[index].region.Width());
	this->m_SetDetectRegionWidth.SetWindowTextW(str);
	str.Format(_T("%d"),m_SysSetPara.dtr[index].threshold);
	this->m_SetDetectThreshold.SetWindowTextW(str);
	m_iCurrentDetectRegionID=index;
	this->Invalidate();
}

void CImageObjectDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO: Add your message handler code here and/or call default
	int pos;
	HRESULT hr;
	VIDEOPROPERTYRANGE vpr;
	if(pScrollBar->m_hWnd == m_ImageContrastSlider.m_hWnd)
	{
		pos = m_ImageContrastSlider.GetPos();
		DSStream_SetVideoPropertyValue(m_CardID, VideoProperty_Brightness, pos*100);
		hr = DSStream_GetVideoPropertyValue(m_CardID, VideoProperty_Brightness, &vpr);
		m_SysSetPara.image_contrast=pos;
		
	}else if(pScrollBar->m_hWnd == m_ImageLightSlider.m_hWnd)
	{
		pos = m_ImageLightSlider.GetPos();
		DSStream_SetVideoPropertyValue(m_CardID, VideoProperty_Brightness, pos*100);
		hr = DSStream_GetVideoPropertyValue(m_CardID, VideoProperty_Brightness, &vpr);
		m_SysSetPara.image_light=pos;
	}
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}


void CImageObjectDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
//	this->m_ShowImage.OnLButtonDown(nFlags, point);
/*	CRect	 rectImage;
	m_ShowImage.GetWindowRect(rectImage);
	CRect reDetectRegionOnScreen;
	CPoint mypoint(0,0);
	m_ShowImage.ClientToScreen(&mypoint);
	this->ScreenToClient(&mypoint);
*/

	for(int i=0;i<m_SysSetPara.detect_num;i++)
	{
		if(DetectRegion[i].PtInRect(point))	
		{
			m_iCurrentDetectRegionID=i;
			m_SelectDetectRegion.SetCurSel(i);
			CString str;
			m_SelectDetectRegion.SetCurSel(m_iCurrentDetectRegionID);
			str.Format(_T("%d"),m_SysSetPara.dtr[m_iCurrentDetectRegionID].region.Height());
			m_SetDetectRegionHeight.SetWindowTextW(str);
			str.Format(_T("%d"),m_SysSetPara.dtr[m_iCurrentDetectRegionID].region.Width());
			m_SetDetectRegionWidth.SetWindowTextW(str);
			str.Format(_T("%d"),m_SysSetPara.dtr[m_iCurrentDetectRegionID].threshold);
			m_SetDetectThreshold.SetWindowTextW(str);
			m_StartPoint=point;
			m_LasterPoint=point;
			m_RegionPosiAdjust=TRUE;
			this->Invalidate();
		}
	}
	/*

	CRect rtRegion=m_SysSetPara.dtr[i].region;
			m_ShowImage.ClientToScreen(rtRegion);
			this->ScreenToClient(rtRegion);
			DetectRegion[i]=rtRegion;
	if(!m_bufferVideo)
	{
		m_bufferVideo=new BYTE[100];
	}
	if(m_SetEnable)
	{
		if(rectImage.PtInRect(point))
		{
			if(DetectRegion[m_iCurrentDetectRegionID].PtInRect(point))
			{
				m_RegionPosiAdjust=TRUE;
				SetCapture();
				m_StartPoint=point;
			}
		}
	}else
	{
		if(rectImage.PtInRect(point))
		{
			for(int i=0;i<m_SysSetPara.detect_num;i++)
			{
				if(DetectRegion[i].PtInRect(point))
				{
					m_iCurrentDetectRegionID=i;
				}
			}
		}
	}
	*/
	CDialog::OnLButtonDown(nFlags, point);
}
void CImageObjectDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	if(m_SetEnable)
	{
		if(m_RegionPosiAdjust)
		{
			int movex,movey;
			movex=point.x-m_StartPoint.x;
			movey=point.y -m_StartPoint.y;
			CRect testRect=DetectRegion[m_iCurrentDetectRegionID];
			CPoint lt(testRect.left,testRect.top );
			testRect.MoveToXY(lt.x+movex,lt.y+movey);
			CPoint newlt(testRect.left ,testRect.top );
			CPoint newbr(testRect.right ,testRect.bottom );
			CRect	 rectImage;
			m_ShowImage.GetWindowRect(rectImage);
			this->ScreenToClient(rectImage);
			if(rectImage.PtInRect(newlt)&&rectImage.PtInRect(newlt))
			{
				DetectRegion[m_iCurrentDetectRegionID]=testRect;
			}
			
			m_RegionPosiAdjust=FALSE;
			testRect=DetectRegion[m_iCurrentDetectRegionID];
			this->ClientToScreen(testRect);
			m_ShowImage.ScreenToClient(testRect);
			m_SysSetPara.dtr[m_iCurrentDetectRegionID].region=testRect;
			this->Invalidate();
		}	
	}
	CDialog::OnLButtonUp(nFlags, point);
}

void CImageObjectDlg::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	/*	CRect	 rectImage;
	m_ShowImage.GetWindowRect(rectImage);
	CRect reDetectRegionOnScreen;
	CPoint mypoint(0,0);
	m_ShowImage.ClientToScreen(&mypoint);
	this->ScreenToClient(&mypoint);
*/
	if(m_SetEnable)
	{
		if(m_RegionPosiAdjust)
		{
			int movex,movey;
			movex=point.x-m_StartPoint.x;
			movey=point.y -m_StartPoint.y;
			CRect testRect=DetectRegion[m_iCurrentDetectRegionID];
			CPoint lt(testRect.left,testRect.top );
			testRect.MoveToXY(lt.x+movex,lt.y+movey);
			CPoint newlt(testRect.left ,testRect.top );
			CPoint newbr(testRect.right ,testRect.bottom );
			CRect	 rectImage;
			m_ShowImage.GetWindowRect(rectImage);
			this->ScreenToClient(rectImage);
			if(rectImage.PtInRect(newlt)&&rectImage.PtInRect(newlt))
			{
				DetectRegion[m_iCurrentDetectRegionID]=testRect;
			}else
			{
				m_RegionPosiAdjust=FALSE;
				testRect=DetectRegion[m_iCurrentDetectRegionID];
				this->ClientToScreen(testRect);
				m_ShowImage.ScreenToClient(testRect);
				m_SysSetPara.dtr[m_iCurrentDetectRegionID].region=testRect;
			}
			this->Invalidate();
		}
	}
	CDialog::OnMouseMove(nFlags, point);
}
void CImageObjectDlg::RectImageToDlg(CRect *lpSource,CRect *lpResult)
{
//	int value;
	double scale;
	CRect reShow;
	m_ShowImage.GetWindowRect(reShow);
	scale=lpSource->top/IMAGE_HEIGHT;
	lpResult->top=(long)(reShow.top+reShow.Height()*scale);
	lpResult->bottom=(long)(reShow.bottom+reShow.Height()*scale);
	scale=lpSource->left/IMAGE_WIDTH;
	lpResult->left=(long)(reShow.left+reShow.Width()*scale);
	lpResult->right=(long)(reShow.right+reShow.Width()*scale);
}
void CImageObjectDlg::RectDlgToImage(CRect *lpSource,CRect *lpResult)
{
//	int value;
	double scale;
	CRect reShow;
	m_ShowImage.GetWindowRect(reShow);
	scale=lpSource->top/IMAGE_HEIGHT;
	lpResult->top=(long)(reShow.top+reShow.Height()*scale);
	lpResult->bottom=(long)(reShow.bottom+reShow.Height()*scale);
	scale=lpSource->left/IMAGE_WIDTH;
	lpResult->left=(long)(reShow.left+reShow.Width()*scale);
	lpResult->right=(long)(reShow.right+reShow.Width()*scale);
}

void CImageObjectDlg::OnEnKillfocusRe2RegionHeight()
{
	// TODO: Add your control notification handler code here
	int end=m_SetDetectNum.GetTextLength();
	CString str;
	m_SetDetectNum.GetTextRange(0,end,str);
	int h=_ttoi(str);
	CPoint lt(m_SysSetPara.dtr[m_iCurrentDetectRegionID].region.left ,m_SysSetPara.dtr[m_iCurrentDetectRegionID].region.top );
	int w=m_SysSetPara.dtr[m_iCurrentDetectRegionID].region.Width();
	CRect newRect(lt.x ,lt.y ,lt.x +w,lt.y +h);
	m_SysSetPara.dtr[m_iCurrentDetectRegionID].region=newRect;
	this->Invalidate();
}

void CImageObjectDlg::OnEnKillfocusRe2RegionWidth()
{
	// TODO: Add your control notification handler code here
	int end=m_SetDetectNum.GetTextLength();
	CString str;
	m_SetDetectNum.GetTextRange(0,end,str);
	int w=_ttoi(str);
	CPoint lt(m_SysSetPara.dtr[m_iCurrentDetectRegionID].region.left ,m_SysSetPara.dtr[m_iCurrentDetectRegionID].region.top );
	int h=m_SysSetPara.dtr[m_iCurrentDetectRegionID].region.Height();
	CRect newRect(lt.x ,lt.y ,lt.x +w,lt.y +h);
	m_SysSetPara.dtr[m_iCurrentDetectRegionID].region=newRect;
	this->Invalidate();
}

void CImageObjectDlg::OnEnKillfocusRe2RegionThreshold()
{
	// TODO: Add your control notification handler code here
	int end=m_SetDetectNum.GetTextLength();
	CString str;
	m_SetDetectNum.GetTextRange(0,end,str);
	int w=_ttoi(str);
	m_SysSetPara.dtr[m_iCurrentDetectRegionID].threshold=w;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -