📄 magicscissorsdoc.cpp
字号:
for( int f = 0 ; f < m_nTotalFrame ; f++ )
{
pInfo = m_pFrameList->GetFrame(f);
if( pInfo == NULL ) continue;
pObjList = pInfo->GetObjList();
if( pObjList == NULL ) continue;
str.Format("[[ Frame No : %d ]]\n", sframe+f+1);
out.WriteString((LPCTSTR)str);
objnum = pObjList->GetTotal();
str.Format("Total Object : %d\n", objnum);
out.WriteString((LPCTSTR)str);
if( m_nMode == 1 )
{
m_pVideo->GetFrame(f, pImage);
}
else
{
CString file;
file.Format("%s%06d.bmp", m_strFileName, m_nStartFrame+f);
pImage->LoadImage(file);
}
ptrsrc = pImage->GetColorPtr();
for( i = 0 ; i < objnum ; i++ )
{
str.Format("[Object ID : %d]\n", i+1);
out.WriteString((LPCTSTR)str);
pRgn = pObjList->GetObject(i);
pPtList = pRgn->GetEdgeList();
ptnum = pPtList->GetLength();
str.Format("Total Edge Point : %d\n", ptnum);
out.WriteString((LPCTSTR)str);
rect = pRgn->GetBound();
str.Format("Rect : %d %d %d %d\n", rect.left,rect.top,rect.right,rect.bottom);
out.WriteString((LPCTSTR)str);
for( j = 0 ; j < ptnum ; j++ )
{
pnt = *(pPtList->GetPoint(j));
str.Format("(%d,%d) ", pnt.x, pnt.y );
out.WriteString((LPCTSTR)str);
if( j != 0 && j % 19 == 0 ) out.WriteString( "\n" );
}
out.WriteString( "\n" );
//rect = pRgn->GetBound();
sx = rect.left;
sy = rect.top;
w = rect.Width()+1;
h = rect.Height()+1;
pObject = new CImage( CSize(w,h), 24, RGB(0,0,0) );
ptrdes = pObject->GetColorPtr();
for( y = 0 ; y < h ; y++ )
{
for( x = 0 ; x < w ; x++ )
{
if( pRgn->PtInRgn( CPoint(sx+x,sy+y) ) )
ptrdes[y][x] = ptrsrc[sy+y][sx+x];
}
}
extname.Format("%06d_%02d.bmp", sframe+f, i+1 );
pObject->SaveImage((LPSTR)(LPCTSTR)(m_strSeg+extname) );
delete pObject;
}
for( i = 0 ; i < objnum ; i++ )
{
pRgn = pObjList->GetObject(i);
pPtList = pRgn->GetEdgeList();
rect = pRgn->GetBound();
sx = rect.left;
sy = rect.top;
w = rect.Width()+1;
h = rect.Height()+1;
for( y = sy ; y < sy+h ; y++ )
{
for( x = sx ; x < sx+w ; x++ )
{
if( pRgn->PtInRgn( CPoint(x,y) ) )
ptrsrc[y][x].r = ptrsrc[y][x].g = ptrsrc[y][x].b = 0;
}
}
}
extname.Format("%06d_99.bmp", sframe+f );
pImage->SaveImage((LPSTR)(LPCTSTR)(m_strSeg+extname) );
out.WriteString( "\n" );
((CProgressCtrl*)pDlg->GetDlgItem(IDC_PROGRESS1))->SetPos(f);
pDlg->UpdateWindow();
count++;
output.Format("%d / %d frames", count, fnum);
pDlg->GetDlgItem(IDC_OUT)->SetWindowText(output);
}
out.Close();
pDlg->ShowWindow(SW_HIDE);
pDlg->DestroyWindow();
delete pDlg;
delete pImage;
}
void CMagicScissorsDoc::FindFrame(int n, BOOL bEdge)
{
//if( !m_pVideo ) return;
if( n < 0 ) return;
if( n >= m_nTotalFrame ) return;
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
pFrame->m_wndOptionBar.UpdateData(TRUE);
int e = pFrame->m_wndOptionBar.m_nEdge;
m_nCurFrame = n;
if( m_pFrameList )
{
if( !m_pFrameList->GetFrame(m_nCurFrame) )
m_pFrameList->AddFrame(m_nCurFrame, m_ImgSize);
m_pCurFrame = m_pFrameList->GetFrame(m_nCurFrame);
}
if( m_nMode == 1 )
{
if( !m_pImage )
m_pImage = m_pVideo->GetFrame( m_nCurFrame );
else
m_pVideo->GetFrame( m_nCurFrame, m_pImage );
}
else if( m_nMode == 2 )
{
CString file;
file.Format("%s%06d.bmp", m_strFileName, m_nStartFrame+m_nCurFrame);
if( m_pImage ) delete m_pImage;
m_pImage = new CImage(file);
if( !m_pImage->IsValidate() )
{
file += "阑 凯荐 绝嚼聪促.";
AfxMessageBox(file);
return;
}
}
if( bEdge )
{
DetectEdge();
/*CImageColor color(m_pImage);
if( m_pEdgeMap )
color.ConvertGray(m_pEdgeMap );
else
m_pEdgeMap = color.ConvertGray(TRUE);
CEdgeDetector edge(m_pEdgeMap);
edge.Edge_Deriche(m_fEdge[e-1]);*/
}
m_nCurFrame++;
if( m_pObjUndoList )
{
delete m_pObjUndoList;
m_pObjUndoList = NULL;
}
if( m_pPolygonList )
{
delete m_pPolygonList;
m_pPolygonList = NULL;
}
m_bEdge = bEdge;
}
void CMagicScissorsDoc::OnCloseDocument()
{
// TODO: Add your specialized code here and/or call the base class
((CMainFrame*)AfxGetMainWnd())->m_wndVideoControlBar.CloseVideo();
CDocument::OnCloseDocument();
}
/*
void CMagicScissorsDoc::MakeStereoImage(float angle)
{
if( !m_pSecond ) return;
COpenGLView* pGL = (COpenGLView*)m_pSecond;
if( m_strLeft == "" )
{
AfxMessageBox("历厘 版肺啊 汲沥登瘤 臼疽嚼聪促.");
return;
}
CString dir = m_strLeft;
int l = dir.ReverseFind('\\');
dir = dir.Left(l);
CFileFind find;
if( !find.FindFile( dir ) )
{
if( ! ::CreateDirectory( dir, NULL ) )
{
AfxMessageBox("叼泛配府甫 父甸 荐 绝嚼聪促.");
return;
}
}
find.Close();
dir = m_strRight;
l = dir.ReverseFind('\\');
dir = dir.Left(l);
if( !find.FindFile( dir ) )
{
if( ! ::CreateDirectory( dir, NULL ) )
{
AfxMessageBox("叼泛配府甫 父甸 荐 绝嚼聪促.");
return;
}
}
find.Close();
dir = m_strStereo;
l = dir.ReverseFind('\\');
dir = dir.Left(l);
if( !find.FindFile( dir ) )
{
if( ! ::CreateDirectory( dir, NULL ) )
{
AfxMessageBox("叼泛配府甫 父甸 荐 绝嚼聪促.");
return;
}
}
find.Close();
//CString basename = m_strVideoFile;
CString extname;
//int l = basename.ReverseFind('.');
//basename = basename.Left(l);
int fnum = m_pFrameList->GetTotal();
int objnum;
CFrameInfo* pInfo;
CObjList* pObjList;
//int w,h, x,y, sx, sy;
CString output;
CWriteObjDlg* pDlg = new CWriteObjDlg;
pDlg->Create(IDD_WRITE_OBJECT);
pDlg->SetWindowText("胶抛饭坷 康惑阑 历厘钦聪促.");
pDlg->m_Progress.SetRange(0, fnum-1);
pDlg->m_Progress.SetPos(0);
output.Format("0 / %d frames", fnum );
pDlg->GetDlgItem(IDC_OUT)->SetWindowText(output);
pDlg->ShowWindow(SW_SHOW);
pDlg->CenterWindow();
int count = 0;
CSize size = m_ImgSize;
int i,j,k;
//float angle = 3.f;
int cx = size.cx/2;
float p,s;
int pos, ppos;
int type;
type = m_pImage->GetColorMode();
CImage* pImage;
CImage* pImageI;
if( type == TRUERGB )
{
pImage = new CImage( size, 24, 0 );
pImageI = new CImage( size, 24, 0 );
}
else
{
pImage = new CImage( size, 8, 0 );
pImageI = new CImage( size, 8, 0 );
}
int sframe = m_nStartFrame;
for( int f = 0 ; f < m_nTotalFrame ; f++ )
{
pInfo = m_pFrameList->GetFrame(f);
if( pInfo == NULL ) continue;
pObjList = pInfo->GetObjList();
if( pObjList == NULL ) continue;
objnum = pObjList->GetTotal();
if( objnum == 0 ) continue;
FindFrame( f );
pGL->Invalidate(FALSE);
pGL->UpdateWindow();
Sleep(100);
pGL->MakeDepthMap(NULL);
if( !m_pDepthmap ) continue;
//m_pDepthmap->SaveImage("d:\\depth.bmp");
BYTE** depth = m_pDepthmap->GetPtr();
if( type == TRUERGB )
{
CColorPixel** src = m_pImage->GetColorPtr();
CColorPixel** des = pImage->GetColorPtr();
CColorPixel** desi = pImageI->GetColorPtr();
for( j = 0 ; j < size.cy ; j++ )
{
ppos = 0;
for( i = 0 ; i < size.cx ; i++ )
{
p = (float)((cx-i)*cos(angle/180.f*PI));
s = (float)(depth[j][i]*sin(angle/180.f*PI));
pos = (int)((cx-p)-s+0.5);
if( pos > 0 && pos < size.cx )
des[j][pos] = src[j][i];
if( pos - ppos > 1 )
{
while(1)
{
ppos++;
if( ppos == pos ) break;
if( i-1 < 0 )
k = i;
else
k = i-1;
des[j][ppos].r = (src[j][i].r+src[j][k].r)/2;
des[j][ppos].g = (src[j][i].g+src[j][k].g)/2;
des[j][ppos].b = (src[j][i].b+src[j][k].b)/2;
}
}
else
ppos = pos;
}
if( j % 2 )
memcpy( desi[j], src[j], sizeof(CColorPixel)*size.cx );
else
memcpy( desi[j], des[j], sizeof(CColorPixel)*size.cx );
}
}
else
{
BYTE** src = m_pImage->GetPtr();
BYTE** des = pImage->GetPtr();
BYTE** desi = pImageI->GetPtr();
for( j = 0 ; j < size.cy ; j++ )
{
for( i = 0 ; i < size.cx ; i++ )
{
p = (float)((cx-i)*cos(angle/180.f*PI));
s = (float)(depth[j][i]*sin(angle/180.f*PI));
pos = (int)((cx-p)-s+0.5);
if( pos > 0 && pos < size.cx )
des[j][pos] = src[j][i];
}
if( j % 2 )
memcpy( desi[j], src[j], size.cx );
else
memcpy( desi[j], des[j], size.cx );
}
}
extname.Format("%06d.bmp", sframe+f );
m_pImage->SaveImage((LPSTR)(LPCTSTR)(m_strLeft+extname) );
extname.Format("%06d.bmp", sframe+f );
pImage->SaveImage((LPSTR)(LPCTSTR)(m_strRight+extname) );
extname.Format("%06d.bmp", sframe+f );
pImageI->SaveImage((LPSTR)(LPCTSTR)(m_strStereo+extname) );
((CProgressCtrl*)pDlg->GetDlgItem(IDC_PROGRESS1))->SetPos(f);
pDlg->UpdateWindow();
count++;
output.Format("%d / %d frames", count, fnum);
pDlg->GetDlgItem(IDC_OUT)->SetWindowText(output);
}
pDlg->ShowWindow(SW_HIDE);
pDlg->DestroyWindow();
delete pDlg;
delete pImage;
delete pImageI;
}*/
void CMagicScissorsDoc::MakeStereoImage(int vpos, int diff)
{
if( !m_pSecond ) return;
COpenGLView* pGL = (COpenGLView*)m_pSecond;
if( m_strLeft == "" )
{
AfxMessageBox("历厘 版肺啊 汲沥登瘤 臼疽嚼聪促.");
return;
}
CString dir = m_strLeft;
int l = dir.ReverseFind('\\');
dir = dir.Left(l);
CFileFind find;
if( !find.FindFile( dir ) )
{
if( ! ::CreateDirectory( dir, NULL ) )
{
AfxMessageBox("叼泛配府甫 父甸 荐 绝嚼聪促.");
return;
}
}
find.Close();
dir = m_strRight;
l = dir.ReverseFind('\\');
dir = dir.Left(l);
if( !find.FindFile( dir ) )
{
if( ! ::CreateDirectory( dir, NULL ) )
{
AfxMessageBox("叼泛配府甫 父甸 荐 绝嚼聪促.");
return;
}
}
find.Close();
dir = m_strStereo;
l = dir.ReverseFind('\\');
dir = dir.Left(l);
if( !find.FindFile( dir ) )
{
if( ! ::CreateDirectory( dir, NULL ) )
{
AfxMessageBox("叼泛配府甫 父甸 荐 绝嚼聪促.");
return;
}
}
find.Close();
//CString basename = m_strVideoFile;
CString extname;
//int l = basename.ReverseFind('.');
//basename = basename.Left(l);
int fnum = m_pFrameList->GetTotal();
int objnum;
CFrameInfo* pInfo;
CObjList* pObjList;
CObjRgn* pRgn;
CEdgeList* pPtList;
CPoint pnt;
CRect rect;
int w,h, x,y, sx, sy;
CString output;
CWriteObjDlg* pDlg = new CWriteObjDlg;
pDlg->Create(IDD_WRITE_OBJECT);
pDlg->SetWindowText("胶抛饭坷 康惑阑 历厘钦聪促.");
pDlg->m_Progress.SetRange(0, fnum-1);
pDlg->m_Progress.SetPos(0);
output.Format("0 / %d frames", fnum );
pDlg->GetDlgItem(IDC_OUT)->SetWindowText(output);
pDlg->ShowWindow(SW_SHOW);
pDlg->CenterWindow();
int count = 0;
CSize size = m_ImgSize;
int i,j,k;
//float angle = 3.f;
int cx = size.cx/2;
float p,s;
int pos, ppos;
int type;
type = m_pImage->GetColorMode();
CImage* pImageR;
CImage* pImageL;
CImage* pImageI;
if( type == TRUERGB )
{
pImageR = new CImage( size, 24, 0 );
pImageL = new CImage( size, 24, 0 );
pImageI = new CImage( size, 24, 0 );
}
else
return;
int sframe = m_nStartFrame;
CImage* pDepthmap;
for( int f = 0 ; f < m_nTotalFrame ; f++ )
{
pInfo = m_pFrameList->GetFrame(f);
if( pInfo == NULL ) continue;
pObjList = pInfo->GetObjList();
if( pObjList == NULL ) continue;
objnum = pObjList->GetTotal();
if( objnum == 0 ) continue;
FindFrame( f );
pGL->Invalidate(FALSE);
pGL->UpdateWindow();
Sleep(100);
pGL->MakeDepthMap(NULL);
if( !m_pDepthmap ) continue;
//m_pDepthmap->SaveImage("d:\\depth.bmp");
int rx,lx;
int rc, lc;
rc = size.cx/2+diff;
lc = size.cx/2;
//lc = size.cx/2+diff/2;
int posl,posr;
pDepthmap = new CImage( size, 8, 0 );
BYTE** sdepth = m_pDepthmap->GetPtr();
BYTE** depth = pDepthmap->GetPtr();
if( type == TRUERGB )
{
*pImageR = *m_pImage;
*pImageL = *m_pImage;
CColorPixel** src = m_pImage->GetColorPtr();
CColorPixel** desr = pImageR->GetColorPtr();
CColorPixel** desl = pImageL->GetColorPtr();
CColorPixel** desi = pImageI->GetColorPtr();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -