📄 seqprocessdlg.cpp
字号:
graph_array[0][i][j].listElem=NULL;
index=temp_cost & Max_cost;
//message.Format("%d %d %d %d",index,k,i,j);
//MessageBox(message);
point_activelist.y=i;
point_activelist.x=j;
index_array[index]=Add_Active_List(index_array[index],point_activelist);
graph_array[0][i][j].listElem=index_array[index];
}
}
}
}m++;
}
k++;
index=(graph_array[0][point_to_expand.y][point_to_expand.x].cumul_cost & Max_cost);
if(point_to_expand!=seed_point){
index_array[index]=index_array[index]->down;
delete graph_array[0][point_to_expand.y][point_to_expand.x].listElem;
}
index=Remove_to_Expand(index,&index_array[0]);
if(index!=Max_cost+1){
point_to_expand=index_array[index]->pixel;
graph_array[0][point_to_expand.y][point_to_expand.x].expand=true;
}
else k=GradientMagnitude[0].ysize*GradientMagnitude[0].xsize;
}while(k<GradientMagnitude[0].ysize*GradientMagnitude[0].xsize-1);
//message.Format("%d %d %d %d %d",k,point_to_expand.y,seed_point.y,point_to_expand.x,seed_point.x);
//message+="expand edildi";
//MessageBox(message);
}
else if((seed_point.x!=-1) && (cost_calculated==TRUE))
{
seed_point2.x=(long)m_posX;
seed_point2.y=(long)m_posY;
seed_array[seed_count].x=(long)m_posX;
seed_array[seed_count].y=(long)m_posY;
seed_count++;
// seed_point2=CursorSnap(seed_point2,GradientMagnitude);
// if(seed_point==seed_point2) finish=true;
dc.SetPixel(point.x,point.y,RGB(0,255,0));
mat_saved(m_posY,m_posX,0)=0;
mat_saved(m_posY,m_posX,1)=255;
mat_saved(m_posY,m_posX,2)=0;
for(i=0;i<GradientMagnitude[0].ysize;i++)
for(j=0;j<GradientMagnitude[0].xsize;j++)
{
graph_array[0][i][j].expand=false;
graph_array[0][i][j].parent=NULL;
graph_array[0][i][j].listElem=NULL;
graph_array[0][i][j].cumul_cost=-1;
}
for(i=0;i<Max_cost+1;i++) index_array[i]=NULL;
graph_array[0][seed_point2.y][seed_point2.x].expand=true;
graph_array[0][seed_point2.y][seed_point2.x].cumul_cost=0;
point_to_expand=seed_point2;
do
{
m=0;
for(i=(point_to_expand.y-1);i<(point_to_expand.y+2);i++)
for(j=(point_to_expand.x-1);j<(point_to_expand.x+2);j++)
{
if((i>=0) && (j>=0) && (i<=GradientMagnitude[0].ysize-1) && (j<=GradientMagnitude[0].xsize-1))
{
point_activelist.y=i;
point_activelist.x=j;
if(graph_array[0][i][j].expand==false)
{
temp_cost=graph_array[0][point_to_expand.y][point_to_expand.x].cumul_cost;
temp_cost+=graph_array[0][point_to_expand.y][point_to_expand.x].local_cost[m];
if(graph_array[0][i][j].parent==NULL)
{
graph_array[0][i][j].cumul_cost=temp_cost;
graph_array[0][i][j].parent=&graph_array[0][point_to_expand.y][point_to_expand.x];
index=temp_cost & Max_cost;
//message.Format("%d %d %d %d",index,k,i,j);
//MessageBox(message);
index_array[index]=Add_Active_List(index_array[index],point_activelist);
graph_array[0][i][j].listElem=index_array[index];
}
else
{
if(temp_cost<graph_array[0][i][j].cumul_cost)
{
index=graph_array[0][i][j].cumul_cost & Max_cost;
graph_array[0][i][j].cumul_cost=temp_cost;
graph_array[0][i][j].parent=&graph_array[0][point_to_expand.y][point_to_expand.x];
Remove(graph_array[0][i][j].listElem,&index_array[index]);
point_activelist=graph_array[0][i][j].listElem->pixel;
delete graph_array[0][point_activelist.y][point_activelist.x].listElem;
graph_array[0][point_activelist.y][point_activelist.x].listElem=graph_array[0][i][j].listElem;
graph_array[0][i][j].listElem=NULL;
index=temp_cost & Max_cost;
//message.Format("%d %d %d %d",index,k,i,j);
//MessageBox(message);
point_activelist.y=i;
point_activelist.x=j;
index_array[index]=Add_Active_List(index_array[index],point_activelist);
graph_array[0][i][j].listElem=index_array[index];
}
}
}
}m++;
}
k++;
index=(graph_array[0][point_to_expand.y][point_to_expand.x].cumul_cost & Max_cost);
if(point_to_expand!=seed_point2){
index_array[index]=index_array[index]->down;
delete graph_array[0][point_to_expand.y][point_to_expand.x].listElem;
}
index=Remove_to_Expand(index,&index_array[0]);
if(index!=Max_cost+1){
point_to_expand=index_array[index]->pixel;
graph_array[0][point_to_expand.y][point_to_expand.x].expand=true;
}
else k=GradientMagnitude[0].ysize*GradientMagnitude[0].xsize;
}while(k<GradientMagnitude[0].ysize*GradientMagnitude[0].xsize-1);
first=NULL;
}
UpdateData(FALSE);
CDialog::OnLButtonDown(nFlags, point);
//return;
}
void CSeqProcessDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//My code:
int i,j;
//CString message="";
//matrix imgSeg;
//ConvertDib2Mat( imgSeg, dibSeq[0]);
finish = true;
seed_point.x=-1;
seed_point.y=-1;
seed_point2.x=-1;
seed_point2.y=-1;
free_point.x=-1;
free_point.y=-1;
first=NULL;
/*for(i=0;i<20;i++)
{
if(seed_array[i].x!=-1)
//message.Format("%f %f %f",imgSeg(seed_array[i].y,seed_array[i].x,0),imgSeg(seed_array[i].y,seed_array[i].x,1),imgSeg(seed_array[i].y,seed_array[i].x,2));
message.Format("%f",LaplacianMap[0](seed_array[i].y,seed_array[i].x,0));
MessageBox(message);
}*/
for(i=0;i<GradientMagnitude[0].ysize;i++)
for(j=0;j<GradientMagnitude[0].xsize;j++)
{
graph_array[0][i][j].expand=false;
graph_array[0][i][j].parent=NULL;
graph_array[0][i][j].listElem=NULL;
graph_array[0][i][j].cumul_cost=-1;
}
for(i=0;i<Max_cost+1;i++) index_array[i]=NULL;
CDialog::OnRButtonDown(nFlags, point);
}
void CSeqProcessDlg::OnFileSaveas()
{
// TODO: Add your command handler code here
CString filename="output.bmp";
SaveAsBmp(mat_saved,filename);
}
void CSeqProcessDlg::OnDenemeSeedtrack()
{
// TODO: Add your command handler code here
int i, k, m,N,upsearch,downsearch;
int fr, frame;
int inouterror,inouterror2;
double distance,angle,CandDistance,CandAngle,GradMagUpAve,GradMagDownAve,GradMagUpStdDev,GradMagDownStdDev;
matrix imgPrev, imgNext;
CPoint seed, seedcand,testseed;
CString filename, message, info;
int search_range_x;
int search_range_y;
int index, count;
int Numcandidate,UpContsize,DownContsize;
struct Contour* temp;
struct SeedCandidate* FirstCandidate;
struct SeedCandidate* LastCandidate;
struct SeedCandidate* NewCandidate;
struct SeedCandidate* Test1;
struct SeedCandidate* Test2;
struct HSI hsi_prev;
struct HSI hsi_next;
struct HSI candhsi;
struct HSI candhsiUp;
struct HSI candhsiDown;
struct HSI seedhsi;
struct HSI seedhsiUp;
struct HSI seedhsiDown;
// go to the first frame, to start motion estimation
// Update the slider display
m_currentframe = m_startframe;
m_sliderframe.SetPos(m_currentframe);
UpdateData(FALSE);
ConvertDib2Mat( imgPrev, dibSeq[0]);
FirstPoint=new Contour;
FirstPoint->boundary=seed_array[0];
FirstPoint->next_point=NULL;
LastPoint=FirstPoint;
for(index=0;index<seed_count;index++)
{
if(index!=0)
{
imgPrev=LiveWireDrawer(seed_array[index-1],seed_array[index],imgPrev,graph_array[0],index_array,LastPoint);
}
Dijkstra(seed_array[index],imgPrev,graph_array[0],index_array);
if(index==seed_count-1)
{
Dijkstra(seed_array[0],imgPrev,graph_array[0],index_array);
imgPrev=LiveWireDrawer(seed_array[0],seed_array[index],imgPrev,graph_array[0],index_array,LastPoint);
}
}
filename.Format("ref.bmp");
SaveAsBmp(imgPrev,filename);
UpContsize=0;
GradMagUpAve=0;
DownContsize=0;
GradMagDownAve=0;
temp=FirstPoint;
while((temp!=NULL) && (temp->boundary!=seed_array[9]))
{
GradMagUpAve+=GradientMagnitude[0](temp->boundary.y,temp->boundary.x);
temp=temp->next_point;
UpContsize++;
}
while(temp!=NULL)
{
GradMagDownAve+=GradientMagnitude[0](temp->boundary.y,temp->boundary.x);
temp=temp->next_point;
DownContsize++;
}
GradMagUpAve/=UpContsize;
GradMagDownAve/=DownContsize;
GradMagUpStdDev=0;
GradMagDownStdDev=0;
temp=FirstPoint;
while((temp!=NULL) && (temp->boundary!=seed_array[9]))
{
GradMagUpStdDev+=pow(GradientMagnitude[0](temp->boundary.y,temp->boundary.x)-GradMagUpAve,2);
temp=temp->next_point;
}
while(temp!=NULL)
{
GradMagDownStdDev+=pow(GradientMagnitude[0](temp->boundary.y,temp->boundary.x)-GradMagDownAve,2);
temp=temp->next_point;
}
GradMagUpStdDev = pow(GradMagUpStdDev/UpContsize,0.5);
GradMagDownStdDev = pow(GradMagDownStdDev/DownContsize,0.5);
for (frame = m_startframe; frame < m_endframe; frame++)
{
if (frame > m_startframe)
OnPlayNext();
fr = frame - m_startframe;
ConvertDib2Mat( imgPrev, dibSeq[fr]); // Convert frame 1 from dib to matrix
ConvertDib2Mat( imgNext, dibSeq[fr+1]);// Convert frame 2 from dib to matrix
FirstCandidate=NULL;
for(index=0;index<seed_count;index++)
{
seed=seed_array[index];
Numcandidate=0;
if(seed.y>=7 && seed.y<=imgPrev.ysize-7)
{
search_range_y=5;
}
else if(seed.y>=5 && seed.y<=imgPrev.ysize-5)
{
search_range_y=3;
}
else if(seed.y>=3 && seed.y<=imgPrev.ysize-3)
{
search_range_y=2;
}
else
{
search_range_y=0;
}
if(seed.x>=7 && seed.x <= imgPrev.xsize-7)
{
search_range_x=5;
}
else if(seed.x>=5 && seed.x <= imgPrev.xsize-5)
{
search_range_x=3;
}
else if(seed.x>=3 && seed.x <= imgPrev.xsize-3)
{
search_range_x=2;
}
else
{
search_range_x=0;
}
while(FirstCandidate!=NULL)
{
NewCandidate=FirstCandidate->nextCand;
delete FirstCandidate;
FirstCandidate=NewCandidate;
}
FirstCandidate=NULL;
for(k=-search_range_y;k<=search_range_y;k++)
for(m=-search_range_x;m<=search_range_x;m++)
{
if(index==0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -