📄 airimgview.cpp
字号:
// airImgView.cpp : implementation of the CAirImgView class
//
#include <afxwin.h>
#include "stdafx.h"
#include "airImg.h"
#include "airImgDoc.h"
#include "airImgView.h"
#include "vlImageProc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAirImgView
IMPLEMENT_DYNCREATE(CAirImgView, CView)
BEGIN_MESSAGE_MAP(CAirImgView, CView)
//{{AFX_MSG_MAP(CAirImgView)
ON_COMMAND(ID_RGB2GRAY, OnRgb2gray)
ON_COMMAND(ID_RGB2HSI, OnRgb2hsi)
ON_COMMAND(ID_SOBEL3, OnSobel3)
ON_COMMAND(ID_LAPLACIAN3, OnLaplacian3)
ON_COMMAND(ID_Linertrans, OnLinertrans)
ON_COMMAND(ID_Threshold, OnThreshold)
ON_COMMAND(ID_Edgedetect, OnEdgedetect)
ON_COMMAND(ID_CircleHough, OnCircleHough)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAirImgView construction/destruction
CAirImgView::CAirImgView()
{
// TODO: add construction code here
disp.flag = false;
}
CAirImgView::~CAirImgView()
{
}
BOOL CAirImgView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CAirImgView drawing
void CAirImgView::OnDraw(CDC* pDC)
{
CAirImgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int Width,Height;
int nIndex,nIndex1;
vlPixel *input;
vlPixel *output;
if(disp.flag)
{
Width=pDoc->m_Width;
Height=pDoc->m_Height;
input = disp.src;
output = disp.dest;
//pDC->StretchBlt(0, 0, Width, Height, input, 0, 0, Width, Height, SRCCOPY );
for(int i=0;i<Height;i++)
for(int j=0;j<Width;j++)
{
nIndex=i*Width*3+j*3;
nIndex1=i*Width+j;
//现实原图像
if (disp.srcformat==RGB||disp.srcformat==HSI)
pDC->SetPixel(j,(Height-i-1),RGB(input[nIndex],input[nIndex+1],input[nIndex+2]));
else if (disp.srcformat==GRAY)
pDC->SetPixel(j,(Height-i-1),RGB(input[nIndex1],input[nIndex1],input[nIndex1]));
//现实处理结果
if (disp.destformat==RGB||disp.destformat==HSI)
pDC->SetPixel(j+Width+10,(Height-i-1),RGB(output[nIndex],output[nIndex+1],output[nIndex+2]));
else if (disp.destformat==GRAY)
pDC->SetPixel(j+Width+10,(Height-i-1),RGB(output[nIndex1],output[nIndex1],output[nIndex1]));
}
CString str1;
str1.Format("objectnum = %d",imgProc.objectnum);
pDC->TextOut(20,Height+30,str1);
for(i=0;i<imgProc.objectnum;i++)
{
str1.Format("(%d,%d,%d),",imgProc.objectcoordinates[i][0],imgProc.objectcoordinates[i][1],imgProc.objectr[i]);
pDC->TextOut(20+(i%4)*100,Height+60+(i/4)*30,str1);
}
for (i=0; i<imgProc.objectnum; i++)
{
pDC->MoveTo(Width+10+imgProc.objectcoordinates[i][0]-5, Height-1-imgProc.objectcoordinates[i][1]);
pDC->LineTo(Width+10+imgProc.objectcoordinates[i][0]+5, Height-1-imgProc.objectcoordinates[i][1]);
pDC->MoveTo(Width+10+imgProc.objectcoordinates[i][0], Height-1-imgProc.objectcoordinates[i][1]-5);
pDC->LineTo(Width+10+imgProc.objectcoordinates[i][0], Height-1-imgProc.objectcoordinates[i][1]+5);
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CAirImgView printing
BOOL CAirImgView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CAirImgView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CAirImgView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CAirImgView diagnostics
#ifdef _DEBUG
void CAirImgView::AssertValid() const
{
CView::AssertValid();
}
void CAirImgView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CAirImgDoc* CAirImgView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAirImgDoc)));
return (CAirImgDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CAirImgView message handlers
void CAirImgView::OnRgb2gray()
{
// TODO: Add your command handler code here
CAirImgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CvlWindow window(0,0,pDoc->m_Width,pDoc->m_Height);
imgProc.vlRgb2Gray(&pDoc->src_vlImage,&window,&pDoc->src_vlGrayImage);
disp.src = pDoc->src_vlImage.pixel;
disp.dest = pDoc->src_vlGrayImage.pixel;
disp.srcformat = RGB;
disp.destformat = GRAY;
disp.flag = true;
InvalidateRect(NULL,FALSE);
}
void CAirImgView::OnRgb2hsi()
{
// TODO: Add your command handler code here
CAirImgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CvlWindow window(50,50,100,100);
imgProc.vlRgb2Hsi(&pDoc->src_vlImage,&window,&pDoc->dest_vlImage);
disp.src = pDoc->src_vlImage.pixel;
disp.dest = pDoc->dest_vlImage.pixel;
disp.srcformat = RGB;
disp.destformat = RGB;
disp.flag = true;
InvalidateRect(NULL,FALSE);
}
void CAirImgView::OnSobel3()
{
// TODO: Add your command handler code here
}
void CAirImgView::OnLaplacian3()
{
// TODO: Add your command handler code here
CAirImgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
float laplacian[9] = {0,-1,0,-1,4,-1,0,-1,0};
CvlWindow window(50,50,100,100);
CvlMask mask;
mask.vlMaskCreate(3,3,laplacian);
imgProc.vlConvolve(&pDoc->src_vlImage,&mask, &window,&pDoc->dest_vlImage);
disp.src = pDoc->src_vlImage.pixel;
disp.dest = pDoc->dest_vlImage.pixel;
disp.srcformat = RGB;
disp.destformat = RGB;
disp.flag = true;
InvalidateRect(NULL,FALSE);
}
//added functions
void CAirImgView::OnLinertrans()
{
// TODO: Add your command handler code here
CAirImgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CvlWindow window(0,0,pDoc->m_Width,pDoc->m_Height);
imgProc.vlLinertrans(&pDoc->src_vlGrayImage,&window,&pDoc->src_vlGrayImage);
disp.src = pDoc->src_vlImage.pixel;
disp.dest = pDoc->src_vlGrayImage.pixel;
disp.srcformat = RGB;
disp.destformat = GRAY;
disp.flag = true;
InvalidateRect(NULL,FALSE);
}
void CAirImgView::OnThreshold()
{
// TODO: Add your command handler code here
CAirImgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CvlWindow window(0,0,pDoc->m_Width,pDoc->m_Height);
imgProc.vlThreshold(&pDoc->src_vlGrayImage,&window,&pDoc->src_vlGrayImage);
disp.src = pDoc->src_vlImage.pixel;
disp.dest = pDoc->src_vlGrayImage.pixel;
disp.srcformat = RGB;
disp.destformat = GRAY;
disp.flag = true;
InvalidateRect(NULL,FALSE);
}
void CAirImgView::OnEdgedetect()
{
// TODO: Add your command handler code here
CAirImgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CvlWindow window(0,0,pDoc->m_Width,pDoc->m_Height);
imgProc.vlEdgedetect(&pDoc->src_vlGrayImage,&window,&pDoc->src_vlGrayImage);
disp.src = pDoc->src_vlImage.pixel;
disp.dest = pDoc->src_vlGrayImage.pixel;
disp.srcformat = RGB;
disp.destformat = GRAY;
disp.flag = true;
InvalidateRect(NULL,FALSE);
}
void CAirImgView::OnCircleHough()
{
// TODO: Add your command handler code here
CAirImgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CvlWindow window(0,0,pDoc->m_Width,pDoc->m_Height);
imgProc.vlCircleHough(&pDoc->src_vlGrayImage,&window,&pDoc->dest_vlGrayImage,20,60);
disp.src = pDoc->src_vlImage.pixel;
disp.dest = pDoc->dest_vlGrayImage.pixel;
disp.srcformat = RGB;
disp.destformat = GRAY;
disp.flag = true;
InvalidateRect(NULL,FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -