/* we want to unify the optical flow
, normal flow (modified version fo lucas.c, include only the Un, instead fo Unx, Uny.) field and Gradient field (created
by a modified version of lucas.c) to a single file. notice that here the original point has been shifted
from the top-left corner to the centre of image plane.
this program aims to read the optical flow, normal flow(Raw) and gradient flow computed by Lucas&Kanade,
then write to one file include x,y, u, v, Un, nx,ny.
take notice that we have a MAX_NO_OF_INPUT constraint!
we use pic_w to represent the number of column!
*/
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define NO_VALUE 100.0
#define SIZE_FLOAT 4 /*size of float*/
#define HEAD_BARRON 24 /*size of the head of output of barron's code in bytes*/
#define MAX_NO_of_INPUT 300*300
malloc_3D_array(float ****pf,int nocol,int norow,int not)/*not is 1 or 2, it is no use here*/
{
int i,j,k;
float ***p;
p=(float ***)malloc((norow)*sizeof(float **));
if (p==NULL)
{
printf("There is no enough space\n");
exit(1);
}
*pf=p;
for (i=0;i<norow;i++)
{
p[i]=(float **)malloc((nocol)*sizeof(float*));
if (p[i]==NULL)
{
printf("There is no enough space\n");
exit(1);
}
}
for(i=0;i<norow;i++)
for(j=0;j<nocol;j++)
{
p[i][j]=(float *)malloc(not*sizeof(float));
}
for(i=0;i<norow;i++)
for(j=0;j<nocol;j++)
for(k=0;k<not;k++)
p[i][j][k]=0.0;
}
void read_Barron_files(char *fname,float ****readin_array,int *P_W,int *P_L,int *F_W,int *F_L,int *o_set)
{
FILE *fp;
int i,j;
float *** T_readin_array; /* use a 3_D array to store the flow value. a[x][y][0or1]*/
int pic_w,pic_l; /*define the width and length of the image. pic_w is the width (column number or pic_x*/
int field_w,field_l; /* size of the field*/
int offset; /*how many pixel from the bundary of image has no field existing*/
int n_of_flow; /*calculate how many pixels are with velocities computed. (to comfirm read correctly)*/
float p_w,p_l,f_w,f_l,o_t; /*temporaryly store the float value read from files*/
if((fp=fopen(fname,"rb"))==NULL)
{
printf("can't open the file: %s!\n",fname);
exit(1);
}
for (i=0;i<(HEAD_BARRON/SIZE_FLOAT);i++)
{
if(i==0) fread(&p_w,SIZE_FLOAT,1,fp);
if(i==1) fread(&p_l,SIZE_FLOAT,1,fp);
if(i==2) fread(&f_w,SIZE_FLOAT,1,fp);
if(i==3) fread(&f_l,SIZE_FLOAT,1,fp);
if(i==4) fread(&o_t,SIZE_FLOAT,1,fp);
if(i==5) fread(&o_t,SIZE_FLOAT,1,fp);
}
pic_w=(int)p_w;
pic_l=(int)p_l;
field_w=(int)f_w;
field_l=(int)f_l;
offset=(int)o_t;
malloc_3D_array(&T_readin_array,pic_w,pic_l, 2);
n_of_flow=0;
for(i=offset;i<pic_l-offset;i++)
for(j=offset;j<pic_w-offset;j++)
{
fread(T_readin_array[i][j],2*SIZE_FLOAT,1,fp);
if(((T_readin_array[i][j][0])!=NO_VALUE)&&((T_readin_array[i][j][1])!=NO_VALUE))
n_of_flow++;
}
*readin_array=T_readin_array;
*P_W=pic_w; /*pic_w refer to number of column*/
*P_L=pic_l;
*F_W=field_w;
*F_L=field_l;
*o_set=offset;
printf("The flow stored in %s has been read into a 3D array which is a %d by %d by 2 (no_of_row*no_of_col*2)\n",fname,pic_l,pic_w);
printf("the number of pixel with flow computed is %d\n",n_of_flow);
printf("%f%% of the pixel point is computed with flow\n",100*(float)n_of_flow/(field_w*field_l));
fclose(fp);
}
void main(int argc, char ** argv)
{
int i,j,k;
int n_of_flow;
float ***Optical_flow;
float ***Normal_flow; /* here we want to read the Un itself, instead of Unx and Uny*/
float ***Gradient_field;
char Output_name[30];
int pic_w,pic_l,field_w,field_l,offset;
int x,y;
float u,v,Un,nx,ny;
FILE *fp;
typedef struct
{
int x;
int y;
float u;
float v;
float Un;
float nx;
float ny;
}myinput;
myinput input[MAX_NO_of_INPUT];
if(argc!=5)
{
printf("\nUsage: %s <Opticalflow file name ><Gradient_field file name><Magnitude of Normal flow file name (Un)><stem name for output file>\n",argv[0]);
exit(1);
}
sprintf(Output_name,"%s.input",argv[4]);
/*float P_of_haveallflow; /*TO represent how many percent image points have both optical and normal flow*/
/*float P_of_correct_o_flow;/*To represent how many percent projection along gradient direction of
optical flow is within 10% difference with normal flow*/
read_Barron_files(argv[1],&Optical_flow,&pic_w,&pic_l,&field_w,&field_l,&offset);
read_Barron_files(argv[2],&Normal_flow,&pic_w,&pic_l,&field_w,&field_w,&offset);
read_Barron_files(argv[3],&Gradient_field,&pic_w,&pic_l,&field_w,&field_l,&offset);
n_of_flow=0;
for(i=offset;i<pic_l-offset;i++)
for(j=offset;j<pic_w-offset;j++)
{
if((Optical_flow[i][j][0]!=NO_VALUE)&&(Normal_flow[i][j][0]!=NO_VALUE))
{
input[n_of_flow].x=j-pic_w/2;/*take notice here!*/
input[n_of_flow].y=-i+pic_l/2;
input[n_of_flow].u=Optical_flow[i][j][0];
input[n_of_flow].v=Optical_flow[i][j][1];
input[n_of_flow].Un=Normal_flow[i][j][0];
input[n_of_flow].nx=Gradient_field[i][j][0];
input[n_of_flow].ny=Gradient_field[i][j][1];
n_of_flow++;
}
}
printf("there are %d image pixel with both optical flow and normal flow\n",n_of_flow);
printf("Writing to output file %s...",Output_name);
fp=fopen(Output_name,"w");
if(fp==NULL)
{
printf("can't open the output file:%s\n",Output_name);
exit(1);
}
for (k=0;k<n_of_flow;k++)
{
fprintf(fp,"%5d %5d %5.5f %5.5f %5.5f %5.5f %5.5f\n",
input[k].x,input[k].y,input[k].u,input[k].v,input[k].Un,input[k].nx,input[k].ny);
}
fclose(fp);
printf("\nfinished!\n");
}
create_input_for_my.rar_3d flow_Computer Vision_Vision
版权申诉
74 浏览量
2022-09-20
13:58:52
上传
评论
收藏 456KB RAR 举报
朱moyimi
- 粉丝: 64
- 资源: 1万+
最新资源
- vscode-1.64.1.tar源码文件
- vscode-1.64.0.tar源码文件
- vscode-1.52.0.tar源码文件
- Music-Player +PlayerActivity+ rockplayer+ SeeJoPlayer 播放器JAVA源码
- vscode-1.46.0.tar源码文件
- 最近很火植物大战僵尸杂交版2.08苹果+安卓+PC+防闪退工具V2+修改工具+高清工具+通关存档整合包更新
- 超级好用的截图工具PixPin,可录制Gif图
- Screenshot_2024-05-21-17-06-42-64_2332cb9b27b851b548ba47a91682926c.jpg
- 毕业设计参考 - 基于树莓派、OpenCV及Python的人脸识别
- node-v18.20.2-linux-arm64
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈