⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 张昆修改.c

📁 摄像头ov7620读取 并支持ARM芯片 获取图像到LCD
💻 C
📖 第 1 页 / 共 3 页
字号:

	label=0;
	while(label<12)
	{

		for(j=0;j<240;j++)
		{
			for(i=0;i<320*3;i++)
			{
				if(*(ptr2+320*3*j+i)==label)
				{
					total[label]++;
				}
			}
		}


		printf("total= %d/n",total[label]);
		if( (total[label]>200) && (total[label]<1000) )
		{
			for(j=0;j<240;j++)
			{
				for(i=0;i<320*3;i++)
				{
					if( (*(ptr2+i+320*3*j))==label )
						*(ptr1+i+320*3*j)=0;
				}
			}

		}

		label++;
	}

}
/*********************************************************************************************************
** Function name:   v4l_close 
** Descriptions: 关闭video   
** Input:  
** Output : 
** Created by:陈超
** Created Date: 2008.03.28
**********************************************************************************************************/
/*int v4l_close1(fb_v4l1 *vd1)
{
	close(vd1->fd);
	return 0;
}
int v4l_close2(fb_v4l2 *vd2)
{
	close(vd2->fd);
	return 0;
}
/*********************************************************************************************************
** Function name:   thin
** Descriptions:    细化(能弥补腐蚀的某种缺陷)
** Input:  *ptr1,  输入的图象数据指针
** Output : 无
** Created by:
** Created Date: 
**********************************************************************************************************
** Modified by:程德芳
** Modified Date: 2007-5-14
*********************************************************************************************************/
void thin(unsigned char *ptr1,unsigned char *ptr2)
{
	int i,j,m,n;
	unsigned char S[5][5];
	unsigned char count;
	int l;

	l=1;
	while(l==1)
	{
		l=0;
		for(i=2;i<240-2;i++)
		{
			for(j=2*3;j<320*3-2*3;j+=3)
			{
				if( (*(ptr1+320*3*i+j))>127 )
					continue;

				for(m=0;m<5;m++)
				{
					for(n=0;n<5;n++)
					{
						if( (*(ptr1+320*3*i+j+320*3*(2-m)+(n-2)*3))>127 )
							S[m][n]=0;
						else
							S[m][n]=1;
					}
				}

				//判断条件1是否成立
				count=S[1][1]+S[1][2]+S[1][3]+S[2][1]+S[2][3]+S[3][1]+S[3][2]+S[3][3];
				if(count<2||count>6)
				{
					*(ptr1+320*3*i+j)=0;
					*(ptr1+320*3*i+j+1)=0;
					*(ptr1+320*3*i+j+2)=0;
					continue;
				}

				//判断条件2是否成立
				count=0;
				if(S[1][2]==0 && S[1][1]==1)
					count++;
				if(S[1][1]==0 && S[2][1]==1)
					count++;
				if(S[2][1]==0 && S[3][1]==1)
					count++;
				if(S[3][1]==0 && S[3][2]==1)
					count++;
				if(S[3][2]==0 && S[3][3]==1)
					count++;
				if(S[3][3]==0 && S[2][3]==1)
					count++;
				if(S[2][3]==0 && S[1][3]==1)
					count++;
				if(S[1][3]==0 && S[1][2]==1)
					count++;


				if(count!=1)
				{
					*(ptr1+320*3*i+j)=0;
					*(ptr1+320*3*i+j+1)=0;
					*(ptr1+320*3*i+j+2)=0;
					continue;
				}

				//判断条件3是否成立
				if(S[1][2]*S[2][1]*S[2][3]!=0)
				{
					count=0;
					if(S[0][2]==0 && S[0][1]==1)
						count++;
					if(S[0][1]==0 && S[1][1]==1)
						count++;
					if(S[1][1]==0 && S[2][1]==1)
						count++;
					if(S[2][1]==0 && S[2][2]==1)
						count++;
					if(S[2][2]==0 && S[2][3]==1)
						count++;
					if(S[2][3]==0 && S[1][3]==1)
						count++;
					if(S[1][3]==0 && S[0][3]==1)
						count++;
					if(S[0][3]==0 && S[0][2]==1)
						count++;

					if(count==1)
					{
						*(ptr1+320*3*i+j)=0;
						*(ptr1+320*3*i+j+1)=0;
						*(ptr1+320*3*i+j+2)=0;
						continue;
					}
				}

				//判断条件4是否成立
				if(S[1][2]*S[2][1]*S[2][3]!=0)
				{
					count=0;
					if(S[1][1]==0 && S[1][0]==1)
						count++;
					if(S[1][0]==0 && S[2][0]==1)
						count++;
					if(S[2][0]==0 && S[3][0]==1)
						count++;
					if(S[3][0]==0 && S[3][1]==1)
						count++;
					if(S[3][1]==0 && S[3][2]==1)
						count++;
					if(S[3][2]==0 && S[2][2]==1)
						count++;
					if(S[2][2]==0 && S[1][2]==1)
						count++;
					if(S[1][2]==0 && S[1][1]==1)
						count++;

					if(count==1)
					{
						*(ptr1+320*3*i+j)=0;
						*(ptr1+320*3*i+j+1)=0;
						*(ptr1+320*3*i+j+2)=0;
						continue;
					}
				}


				*(ptr2+320*3*i+j)=*(ptr1+320*3*i+j);
				*(ptr2+320*3*i+j+1)=*(ptr1+320*3*i+j+1);
				*(ptr2+320*3*i+j+2)=*(ptr1+320*3*i+j+2);
				
			}
		}
		//memcpy(ptr1,ptr2,320*3*240);
	}
}
/**************************************************************************************************************
                                          main函数

***************************************************************************************************************/
int main( void )
{
	fb_v4l1 vd1;
    fb_v4l2 vd2;
int ret1,ret2,i,j,k,l,k1,c,p;
int z=0;
	
  
float D,D1,D2;
double zpz=0;
float jingtouchang=5;
float d=145;
float f=1.5;


int count=0;
double zp1=0,zp2=0;
//unsigned char   R1,G1,B1,Y1;
//unsigned char   R2,G2,B2,Y2;    
unsigned  char  *ptr;
	unsigned  char  *ptr0;
	unsigned  char  *ptr1;
    unsigned  char  *ptr2;
	unsigned  char  *ptr3;
	unsigned  char  *ptr4;
	unsigned  char  *ptr5;
	unsigned  char  *ptr6;
	unsigned  char  *ptr7;
	unsigned  char  *ptr8;
	unsigned  char  *ptr9;   
	unsigned  char  *ptr10;
	unsigned  char  *ptr11;
	unsigned  char  *ptr12;
	unsigned  char  *imageptr1;
	unsigned  char  *imageptr2;
	unsigned  char  *imageptr3;
	unsigned  char  *imageptr4;
for(c=0;c<2;c++)	              
{
	switch(c)	
	{
    case 0:
	ret1 = open_framebuffer1(FB_FILE,&vd1);		    // 打开FrameBuffer设备
	ret1 = open_video1( V4L_FILE0, &vd1,24,VIDEO_PALETTE_RGB24,320,240 );
	   if( 0!= ret1 )			                        // 打开视频设备失败
	   {
		goto err1;
	   }
    
	printf(vd1.capability.name);
	printf(", Type:%d\n",vd1.capability.type);
	printf("Maxwidth:%d,Maxheight:%d\n",vd1.capability.maxwidth ,vd1.capability.maxheight);
	printf("Minwidth:%d,Minheight:%d\n",vd1.capability.minwidth,vd1.capability.minheight);
	printf("Channels:%d,Audios:%d\n",vd1.capability.channels,vd1.capability.audios);

        for(z=0;z<10;z++)    
		{  imageptr1= get_frame_address1( &vd1 );
		   imageptr2= get_frame_address1( &vd1 );
		   ptr= get_frame_address1( &vd1 );
	       ptr1= get_frame_address1( &vd1 );
		   ptr2= get_frame_address1( &vd1 );
		   ptr3= get_frame_address1( &vd1 );
           ptr4= get_frame_address1( &vd1 );
		   ptr5= get_frame_address1( &vd1 );
		   ptr6= get_frame_address1( &vd1 );
		
		   grey(ptr1,ptr2);
		   gao_la24(ptr2,ptr3);
		   thin(ptr3,ptr4);
		   prewitt0(ptr4,ptr6,0.8);
		   //line(ptr5,ptr6);
		  // gao_la24(ptr5,ptr6);
		   for(j=0;j<240;j++)
		   {
		    	for(i=0;i<320;i++)
				{   
				*(imageptr2+i+j*320)=((*(ptr6+3*i+j*320*3)&0xC0)>>6)|((*(ptr6+(3*i+1)+j*320*3)&0xE0)>>3)|((*(ptr6+(3*i+2)+j*320*3)&0xE0));
				//(ptr+i*3+1+j*320*3)=((*(imageptr1+3*i+j*320*3)&0x1c)<<3)|(*(imageptr1+(3*i+1)+j*320*3)&0x1c)|((*(imageptr1+(3*i+2)+j*320*3)&0x30)>>4);
				//(ptr+i*3+2+j*320*3)=((*(imageptr1+3*i+j*320*3)&0x03)<<5)|((*(imageptr1+(3*i+1)+j*320*3)&0x03)<<2)|((*(imageptr1+(3*i+2)+j*320*3)&0x03));
						
				}
		   }
		   
		   rgb_to_framebuffer1(&vd1,320,240,0,0,imageptr2);
	       if(get_next_frame1( &vd1 ) !=0 )	
			{	// 获取图像数据出错
					goto err1;
			}		
		}		
  close(vd1.fd);
 
  break;
  case 1:
	ret2 = open_framebuffer2(FB_FILE,&vd2);		    // 打开FrameBuffer设备
	ret2 = open_video2( V4L_FILE1, &vd2,24,VIDEO_PALETTE_RGB24,320,240 );
	    if( 0!= ret2 )			                        // 打开视频设备失败
		{
	    	goto err2;
		}
	    printf(vd2.capability.name);
	    printf(", Type2:%d\n",vd2.capability.type);
	    printf("Maxwidth2:%d,Maxheight2:%d\n",vd2.capability.maxwidth ,vd2.capability.maxheight);
	    printf("Minwidth2:%d,Minheight2:%d\n",vd2.capability.minwidth,vd2.capability.minheight);
	    printf("Channels2:%d,Audios2:%d\n",vd2.capability.channels,vd2.capability.audios);
    for(z=15;z>0;z--)
	{
	
		imageptr3= get_frame_address2( &vd2 );
		imageptr4= get_frame_address2( &vd2 );
		ptr7= get_frame_address2( &vd2 );//获取帧地址.调用该函数可以获取当前帧的缓冲地址
		ptr8= get_frame_address2( &vd2 );
		ptr9= get_frame_address2( &vd2 );
		ptr10= get_frame_address2( &vd2 );
        ptr11= get_frame_address2( &vd2 );
        ptr12= get_frame_address2( &vd2 );
	    grey(ptr7,ptr8);
		gao_la24(ptr8,ptr9);
		thin(ptr9,imageptr3);
		prewitt0(imageptr3,imageptr4,0.8);
		//line(ptr11,imageptr4);
		for(j=0;j<240;j++)
		   {
		    	for(i=0;i<320;i++)
				{   
				*(ptr10+i+j*320)=((*(imageptr4+3*i+j*320*3)&0xC0)>>6)|((*(imageptr4+(3*i+1)+j*320*3)&0xE0)>>3)|((*(imageptr4+(3*i+2)+j*320*3)&0xE0));
				//(ptr+i*3+1+j*320*3)=((*(imageptr1+3*i+j*320*3)&0x1c)<<3)|(*(imageptr1+(3*i+1)+j*320*3)&0x1c)|((*(imageptr1+(3*i+2)+j*320*3)&0x30)>>4);
				//(ptr+i*3+2+j*320*3)=((*(imageptr1+3*i+j*320*3)&0x03)<<5)|((*(imageptr1+(3*i+1)+j*320*3)&0x03)<<2)|((*(imageptr1+(3*i+2)+j*320*3)&0x03));
						
				}
		   }
		 
		/* for(j=0;j<240;j++)
		   {
		    	for(i=0;i<320;i++)
				{   
				*(ptr5+i+j*320)=((*(imageptr2+3*i+j*320*3)&0xC0)>>6)|((*(imageptr2+(3*i+1)+j*320*3)&0xE0)>>3)|((*(imageptr2+(3*i+2)+j*320*3)&0xE0));
				//(ptr+i*3+1+j*320*3)=((*(imageptr1+3*i+j*320*3)&0x1c)<<3)|(*(imageptr1+(3*i+1)+j*320*3)&0x1c)|((*(imageptr1+(3*i+2)+j*320*3)&0x30)>>4);
				//(ptr+i*3+2+j*320*3)=((*(imageptr1+3*i+j*320*3)&0x03)<<5)|((*(imageptr1+(3*i+1)+j*320*3)&0x03)<<2)|((*(imageptr1+(3*i+2)+j*320*3)&0x03));
						
				}
		   }*/
		//prewitt0(ptr10,imageptr4,1.5);
		//gao_la24(imageptr4,ptr11);
	rgb_to_framebuffer2(&vd2,320,240,0,0,ptr10);
	    if(get_next_frame2( &vd2 ) !=0 )	
		{	// 获取图像数据出错
	    	goto err2;
		}	
	}
}
}		
/*for(j=126;j<127;j++)
{
			
	for (i=100;i<200;i++)
	{
			R1=*(ptr1 + 3*i + j*320*3);//灰度处理
		    G1=*(ptr1+(3*i+1)+j*320*3);
			B1=*(ptr1+(3*i+2)+j*320*3);
			Y1=(9798*R1+19235*G1+3735*B1)/32768;               
			*(ptr1 + 3*i + j*320*3)=Y1;
			*(ptr1+(3*i+1)+j*320*3)=Y1;
			*(ptr1+(3*i+2)+j*320*3)=Y1;
			if(Y1<50)
			*(ptr2 + i + j*320)=Y1;
			else
			{*(ptr2 + i + j*320)=255;}
			
			
			
			R2=*(ptr6 + 3*i + j*320*3);//灰度处理
		    G2=*(ptr6+(3*i+1)+j*320*3);
			B2=*(ptr6+(3*i+2)+j*320*3);
			Y2=(9798*R2+19235*G2+3735*B2)/32768;               
			*(ptr6 + 3*i + j*320*3)=Y2;
			*(ptr6+(3*i+1)+j*320*3)=Y2;
			*(ptr6+(3*i+2)+j*320*3)=Y2;
			if(Y2<50)
			*(ptr7 + i + j*320)=Y2;
			else
			*(ptr7 + i + j*320)=255;			
	}
}*/

for(p=0;p<3;p++)
{
D1=0;
for(j=60;j<180;j++)
{
	k1=0;		
	for (i=80;i<280;i++)
	{
               //printf("%d,%d\n",*(ptr3+i+j*320),*(ptr7+k+j*320));

			
	  //for(l=j-3;l<j+3;l++)
			//{
		       for(k=k1;k<320;k++)  
			   {
				
					if((k>0)&&(k<320))//&&(l>0)&&(l<240))
					{
						if((*(imageptr2+i+j*320)==*(ptr10+k+j*320))&&(*(imageptr2+i+j*320)>30)&&(i-k>28)&&(i-k<100))//&&(*(ptr6+i+j*320)==*(ptr12+i+j*320)))
						
						{
							
							D=(i-k)/3.2*jingtouchang;
							if(D1==0)
							{
							count++;
							zp1+=(d*f)/D;
							D1=D;
		                    printf("zp1 %f,%d,%d,%d,%f\n",zp1,i,j,k,D);
							}
							else if((D1/D<1.5)&&(D/D1<1.5))
							{
							count++;
							zp2+=(d*f)/D;
							D1=D;
		                    printf("%f,%d,%d,%d,%fdik\n",zp2,i,j,k,D);
							}
							
							k1=k+1;
							k+=320;	
						}
					}
				}
		}
	}

	
    zpz+=(zp1+zp2)/count;
}
zpz=zpz/3;
count=count/3;
	printf("共有匹配点%d个,所测距离为%f m\n",count,zpz);


err1:
	if(vd1.fbfd)
		close(vd2.fbfd);				                        // 关闭FrameBuffer设备

	if(vd1.fd)
		close(vd1.fd);
	exit(0);
	return 0;

err2:
	if(vd2.fbfd)
		close(vd2.fbfd);				                        // 关闭FrameBuffer设备

	if(vd2.fd)
		close(vd2.fd);
	exit(0);
return 0;
}	

	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -