📄 hough.c
字号:
} } } for(i = 0; i < N_n; i++) for(j = 0; j < M_m; j++) if(p[i][j] > hough_thresh) { printf("p[%d][%d]=%d\n",i,j,p[i][j]); //drawline(i,j,SQRTD); }/**************************************** Ipos p1 ; Ipos p2 ; tv_set_overlay(tv2); tv_set_color(tv2,red); tv_line(tv2,p1,p2); tv_reset_draw(tv2); int **flagstar = (int **)int_matrix(N_n, M_m); int **flagend = (int **)int_matrix(N_n, M_m); for(k = 0;k < N_n;k++) for( l = 0;l < M_m ; l ++) { flagstar[k][l] = 0; flagend[k][l] = 0; }/*****************************************//*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*//*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/int flagstart ;int flagend ; for(k = 0;k < N_n;k++) for( l = 0;l < M_m ; l ++) { y = (float)0.0; if ( p[k][l] > hough_thresh ) { flagstart = 0; flagend = 0; line_stack *line_node; line_node=(line_stack*)malloc(sizeof(line_stack)); for ( i = 0 ; i < N1 ;i ++) { r = (float)l*2.0*SQRTD/(M_m-1) - SQRTD; if ( SIN [k] == (float)0.0) y++; else y = (r - (float ) i * COS[k]) / SIN[k]; y +=0.5; j = floor(y); if(j >= 0 && j < N2) if( xin[i][j] == 1) {/***************************************************************************/ if(flagstart == 0) { line_node->ending1=ipos(j,i); flagstart = 1; } line_node->ending2=ipos(j,i);/*******************************************************************************/ //break; //xout[i][j] = 1; } }/*************************************************************************** for ( i = N1 ; i > 0 ;i --) { r = (float)l*2.0*SQRTD/(M_m-1) - SQRTD; if ( SIN [k] == (float)0.0) y++; else y = (r - (float ) i * COS[k]) / SIN[k]; y +=0.5; j = floor(y); if(j >= 0 && j < N2) if( xin[i][j] == 1) { //if(flagend == 0) { line_node->ending2=ipos(j,i); flagend = 1; } break; //xout[i][j] = 1; } }/*******************************************************************************/ line_node->next=first_line_node->next; first_line_node->next=line_node; } }
/*******************************************************************************
for (drow = y1; drow < y2; ++drow)
for (dcol = x1; dcol < x2; ++dcol)
{
if(xout[drow][dcol] == 1) gl_new = 0; else gl_new = 255; //tv_set_color(tv2,red); im_put_pixf(gl_new, im_new1, drow, dcol); } /*******************************************************************************/
}//if //free_int_matrix(xin,N1); //free_int_matrix(xout,N1); //free_int_matrix(p,N_n); //im_new1 = imf_scale(im_new1, 0.0, 255.0); //tv_imrect2(tv2, im_new1);
}/* Tv choice callback. Set the Tv on which the next TvTool will be installed. */
static void tv_choice_proc(choice)
int choice;
{
switch (choice)
{
case 0: tv_set_next(tv);
break;
case 1: tv_set_next(tv1);
break;
case 2: tv_set_next(tv2);
break;
default:error("tv_choice_proc: unknown choice\n", warning);
break;
}
}
/* Draw (or undraw) big dot in selected Tv */
static void bigdot_proc()
{
static Ipos ipos = {0, 0};
Ipos p1 = {0,0}; Ipos p2 = {512,128}; Ipos p3 = {128,1024}; int radius = 15;
tv_set_overlay(tv1); tv_line(tv1, p1, p2 ); tv_rect(tv1, p1, p3); tv_circle(tv1, p2, radius);
tv_bigdot(tv1, ipos, 9);
tv_reset_draw(tv1); int i=0,j; int arratest[10]={5,8,4,7,6,9,4,7,1,17}; while(arratest[i]) format("%d ", arratest[i++]); format("\n"); sorting(arratest,10); i=0; while(arratest[i]) format("%d ", arratest[i++]); format("\n"); int **ptest=(int **)int_matrix(5, 5); for(i = 0; i < 5; i ++){ for( j = 0; j < 5; j ++){ ptest[i][j]=17; format("%d ",ptest[i][j]); } format("\n"); }
}static void draw_proc(){ /*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ pp=first_line_node->next; //int test1 = 0; while(pp!=NULL) { //printf("test1=\n"); //scanf("%d",&test1); //if(test1==1) { tv_set_color(tv2,red); tv_line(tv2,pp->ending1,pp->ending2); tv_set_color(tv2,blue); tv_dot(tv2,pp->ending1); tv_dot(tv2,pp->ending2); printf("red lines\n"); printf("(%d,%d)----(%d,%d)\n", pp->ending1.x,pp->ending1.y,pp->ending2.x,pp->ending2.y); q=pp; pp=pp->next; first_line_node->next=pp; free(q); } }/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/}/* Help */static void help_proc()
{
int i = 0;
static char *help[] =
{
"Ensure you have a Stereo Tool (hit Stereo)",
"Load Stereo tool's default image (hit input)",
"Push the image onto Tina's stack (push)",
"Ensure you have a TvTool",
"Install the TvTool on the image processing tool's tv",
"(hit Hough tool Tv, then hit install)",
"Either: Show or Detect line",
NULL,
};
while(help[i]) format("%s\n", help[i++]);
}
static void drawline(theta,rho,SQRTD)double theta;double rho;float SQRTD;{ int N_n = 180; int M_m = SQRTD; int i;float y1,y2,r; float COS[N_n],SIN[N_n]; float th; for ( i = 0; i < N_n; i++) { th=(float) i * 180.0 / (N_n-1)-90; th= th*R_TO_D; COS[i] = ( double )cos((double)th); SIN[i] = ( double )sin((double)th); //printf("i = %d,COS=%3.2f,SIN=%3.2f\n",i,COS[i],SIN[i]); }/*-90<=theta<=90*/r = (float)rho*2.0*SQRTD/(M_m-1) - SQRTD; //y1 = (r - (float ) 10 * COS[theta]) / SIN[theta]; //y2 = (r - (float ) 102 * COS[theta]) / SIN[theta];y1= 100;y2= 100; Ipos p1 = {10,y1}; Ipos p2 = {100,y2}; tv_set_overlay(tv); tv_set_color(tv,red); tv_line(tv,p1,p2); tv_reset_draw(tv);//printf("hi");}/*-------ascending numerical order-------*/static void sorting(data,n)
float data[]; int n;
{
int i, j, min; float dmin;
for(i=0; i<n-1; i++)
{
min = i; dmin = data[i];
for(j=i+1; j<n; j++)
if(data[j]<dmin) { min = j; dmin = data[j]; }
data[min] = data[i]; data[i] = dmin;
}
}/*____________________ int_matrix _________________________*/
int **int_matrix(row, col)
int row, col;
{
int i,**m;
m=(int **)malloc((unsigned) (row*sizeof(int*)));
for(i=0; i<row; i++)
{
m[i]=(int *)malloc((unsigned) (col*sizeof(int)));
if (!m[i]) error("allocation failure 2 in int_matrix()", non_fatal);
}
return m;
}/*_______________________ free_int_matrix ____________________*/
void free_int_matrix(m,row)
int **m;
int row;
{
int i;
for(i=0; i<row; i++) free((int*) m[i]);
free((int*) m);
}/*-----------------save the param-space and result-----------------------*/static void save_param_proc(){ FILE *fp; if((fp=fopen("param_space","w"))==NULL) { format("Can't open the file!\n"); exit(0); } void *picture; if (tv1 == NULL || tv1->tv_screen == NULL || fp == NULL) return; picture = tv_get_picture(tv1); picture_write(fp, picture); picture_free(picture); fclose(fp);}
static void save_result_proc(){ FILE *fp; if((fp=fopen("hough_result","w"))==NULL) { format("Can't open the file!\n"); exit(0); } void *picture; if (tv2 == NULL || tv2->tv_screen == NULL || fp == NULL) return; picture = tv_get_picture(tv2); picture_write(fp, picture); picture_free(picture); fclose(fp);}static void open_param_proc(){ FILE *fp; void *picture; if((fp=fopen("param_space","r"))==NULL) { format("Can't open the file!\n"); exit(0); } picture= tv_picture_read(tv2, fp); tv_show_picture(tv2,picture); fclose(fp);}static void open_result_proc(){ FILE *fp; void *picture; if((fp=fopen("hough_result","r"))==NULL) { format("Can't open the file!\n"); exit(0); } picture=tv_picture_read(tv2, fp); tv_show_picture(tv2,picture); fclose(fp);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -