在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1746|回复: 2

[原创] 其实是一个识别功能,中转一下,你们不要下载

[复制链接]
发表于 2012-1-18 13:52:52 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
module OutMod(
    rst,
clk,
    clkp,
    clkv,
    clkh,
AorB,
Din,
switch,

Dclk,
Dout

);
input          rst;
input          clk;
input          clkp;
input          clkv;
input          clkh;
input          switch;
input          AorB;
input[7:0]     Din;
output          Dclk;
output[8:0]     Dout;

reg[8:0]        Dout;
reg[2:0]        OutOrder;
reg             copy_v;
reg             copy_h;
reg             hen;
reg             Yen;
reg             frame_logo;

reg               time_en;
reg[1:0]          outByte;
reg               AnalysisEnd;
reg[8:0]             y_Num;
reg[9:0]             x_Num;
reg                  Byte_add;
//reg[8:0]             yBuf;
reg[9:0]             xBuf;
reg[9:0]             xBufA;
reg[9:0]             xBufB;
reg[9:0]             xBufC;
//reg[9:0]             xBufD;
reg[9:0]             y_out;
reg[9:0]             x_out;
//reg[7:0]             max_Dbuf;
wire            Add_en;
wire            Dclk;
wire            en_v;
wire            en_h;
parameter     YUYV   =  1'b0;
parameter     S0   =  3'b000, S1   =  3'b001, S2   =  3'b010, S3   =  3'b011, S4   =  3'b100 ;
parameter     SS0  = 2'b00,  SS1   =   2'b01, SS2  =   2'b10, SS3  =  2'b11;

assign    Add_en    =  !Byte_add & y_Num[5];
assign    en_v      =  !copy_v & clkv;
assign    en_h      =  !copy_h & clkh;
assign    Dclk      =  Byte_add;

always @(posedge clkp) begin
    if(rst == 1'b0) begin
     OutOrder   <=  1'b0;   //
  frame_logo <= 1'b0;
end
else  begin
     copy_v  <=  clkv;
     if(en_v == 1'b1) begin
      frame_logo  <= !frame_logo;
      if((OutOrder[2] == 1'b1)||(switch == 1'b0))
       OutOrder  <=  1'b0;
   else
             OutOrder  <=  OutOrder + 1'b1;
     end
end
end

always @(posedge clkp) begin
    if(clkv == 1'b0) begin
     y_Num <= 1'b0;
end
else begin
     copy_h <= clkh;
     if(en_h == 1'b1)
      y_Num <= y_Num + 1'b1;
end


if(clkh == 1'b0) begin
     x_Num <= 1'b0;
     Yen   <= 1'b0;
end
else  begin
     Yen   <= !Yen;
     if(Yen == YUYV)
         x_Num <= x_Num + 1'b1;
end
end
reg          h_begin;
reg[2:0]     inNum;
always @(posedge clk) begin
    if(clkv == 1'b0) begin
     inNum  <= 1'b0;
end
else begin
  if(clkh == 1'b0) begin
      h_begin  <= 1'b0;
   if(h_begin == 1'b1)
       inNum <= inNum + !inNum[2];
  end
     else if(max == 1'b1) begin
   yBuf     <= y_Num;
   h_begin  <= 1'b1;
  end
    end
end
always @(posedge clk) begin
if({clkh,h_begin} == 2'b01) begin
  xBufA    <= xBuf;
  xBufB    <= xBufA;
  xBufC    <= xBufB;
  //xBufD    <= xBufC;
end
if(AnalysisEnd == 1'b0) begin
     if(OutOrder[0] == 1'b1) begin
      if({max,h_begin} == 2'b10)    // get coordinates of the left boundary, Boundary scan of 4 points
          xBuf    <= x_Num;
     end
     else begin
         if(max == 1'b1)      // get coordinates of the right boundary,Boundary scan of 4 points
          xBuf     <= x_Num;
     end
    end
end
wire[9:0]  summand;
wire[9:0]  Sum;
assign  summand = (OutOrder[1] == 1'b1) xBufC : xBufA;  // 1, 4 ; 2, 3;
assign  Sum = summand + 2'b10;  // Scanning the slope of the corner : 45°
always @(posedge clkp) begin
    if(clkv == 1'b0) begin
     AnalysisEnd  <=  1'b0;
        if(AnalysisEnd != 1'b0) begin
         x_out  <= xBufC;
      y_out  <= {frame_logo,y_Num};
     end
end
else if({AnalysisEnd,inNum[2]} == 2'b01) begin
     case(OutOrder)
         S0  :   
   
         S1  : if(xBufC <= Sum)
                     AnalysisEnd  <=  1'b1;
     
         S2  : if(xBufA <= Sum)
      AnalysisEnd  <=  1'b1;
      
         S3  : if(xBufA >= Sum)
      AnalysisEnd  <=  1'b1;  
     
         S4  : if(xBufC >= Sum)
      AnalysisEnd  <=  1'b1;   
   default: ;
  endcase
end
end

always @(posedge clkp) begin
if(clkv == 1'b0) begin
     outByte  <=  1'b0;
end
else begin
     Byte_add  <= y_Num[5];
  if(Add_en == 1'b1) begin
            if(outByte == 2'b11)
          time_en  <=  1'b0;
   else begin
       time_en  <=  1'b1;
       outByte  <=  outByte + 1'b1;
   end
  end
end
end

always @(posedge clkp) begin
    if(Add_en == 1'b1) begin
     case(outByte)
      SS0 :  if(OutOrder == S1)
               Dout  <=  {y_out[9],8'hff};
       else
            Dout  <=  {y_out[9],6'b0, x_out[9:8]};
      
      SS1 :  if(OutOrder == S1)
               Dout  <=  {y_out[9],8'hff};
       else
            Dout  <=  {y_out[9],x_out[7:0]};
      
      SS2 :  Dout  <=  {y_out[9],7'b0, y_out[8]};
  
      SS3 :  Dout  <=  {y_out[9],y_out[7:0]};
   
      default : ;
  endcase
end
end
endmodule
 楼主| 发表于 2012-7-3 10:48:18 | 显示全部楼层
回复 1# jiangyq

60.rar

2.88 KB, 下载次数: 2 , 下载积分: 资产 -2 信元, 下载支出 2 信元

 楼主| 发表于 2012-7-4 14:37:56 | 显示全部楼层
#include "initial.h"

extern unsigned int coordxBuff[4];
extern unsigned int coordyBuff[4];
extern unsigned char coordNum;


typedef struct {
unsigned char  SmallMove;
unsigned char  state;
unsigned int   x;
unsigned int   y;
} coord;



typedef  struct {
unsigned char   Num;
unsigned int   x;
unsigned int   y;
} CoordInitial;


xdata  CoordInitial  CoordInitialBuff[10];
xdata  coord  coordA;


void InitialStruct(void)
{
    unsigned char i;
   
    for(i = 0; i < 10; i++)
    {
        CoordInitialBuff[i].Num = 0;
    }
}


void FilterCoord(unsigned char Num)  //提取有效数据并确定数据状态
{
    unsigned char i,m;
        unsigned char SaveNum;
        unsigned char free;
       
        xdata unsigned int alensub;
        xdata unsigned int blensub;
       
        if(start_3s == 0)  // 获得3秒内的所有坐标
        {
            for(i = 0; i < Num; i++)
            {
                SaveNum = 0xff;
                        free    = 0xff;
                    for(m = 0; m < 10; m++)
                    {
                        if(CoordInitialBuff[m].Num == 0)
                            {
                                SaveNum = m;
                                    continue;
                }
                               
                            if(coordxBuff[i] > CoordInitialBuff[m].x)
                                    alensub = coordxBuff[i] - CoordInitialBuff[m].x;
                                else
                                    alensub = CoordInitialBuff[m].x - coordxBuff[i];
                               
                                if(alensub > 20)  //无法匹配
                    continue;
                                       
                            if(coordyBuff[i] > CoordInitialBuff[m].y)
                                    alensub = coordyBuff[i] - CoordInitialBuff[m].y;
                                else
                                    alensub = CoordInitialBuff[m].y - coordyBuff[i];
                               
                                if(alensub > 20)  //无法匹配
                    continue;
                           
                free  = 0;                               
                            CoordInitialBuff[m].x = coordxBuff[i];
                            CoordInitialBuff[m].y = coordyBuff[i];                       
                            if(CoordInitialBuff[m].Num < 200)
                                CoordInitialBuff[m].Num++;       
                                       
                break;                                       
                    }
                   
                    if(free == 0xff)
                        {
                            if(SaveNum != 0xff)
                        {
                                CoordInitialBuff[m].Num    = 1;
                                CoordInitialBuff[m].x = coordxBuff[i];
                                CoordInitialBuff[m].y = coordyBuff[i];               
                        }
                        }
            }
                return;
        }

        free = 0;
         
        for(i = 0; i < Num; i++)  // 去掉已经在3秒内出现的坐标
        {
                for(m = 0; m < 10; m++)
                {
                    if(CoordInitialBuff[m].Num == 0)
                                continue;       
                               
                    if(coordxBuff[i] > CoordInitialBuff[m].x)
                            alensub = coordxBuff[i] - CoordInitialBuff[m].x;
                        else
                            alensub = CoordInitialBuff[m].x - coordxBuff[i];
                       
                        if(alensub > 20)  //无法匹配
                continue;
                               
                    if(coordyBuff[i] > CoordInitialBuff[m].y)
                            alensub = coordyBuff[i] - CoordInitialBuff[m].y;
                        else
                            alensub = CoordInitialBuff[m].y - coordyBuff[i];
                       
                        if(alensub > 20)  //无法匹配
                continue;
                       
                        free |= 0x01 << i;         //记录被清除的位置
                       
                        break;
                }         
        }
       
        alensub = 0xffff;
        SaveNum = 0;
       
        for(i = 0; i < Num; i++)  // 获得离上一次最近的坐标
        {
                if(free & (0x01 << i)) // 该坐标已经被清除
                    continue;
               
        if(coordA.x >= coordxBuff[i])               
                    blensub =  coordA.x - coordxBuff[i];
                else
                    blensub =  coordxBuff[i] - coordA.x;
               
        if(coordA.y >= coordyBuff[i])               
                    blensub +=  coordA.y - coordyBuff[i];
                else
                    blensub +=  coordyBuff[i] - coordA.y;       

        if(alensub >= blensub)
        {               
            alensub = blensub;
            SaveNum = i;
        }                       
        }
       
        if(alensub < 10)    // 没有移动
                coordA.SmallMove++;
        else
            coordA.SmallMove = 0;
       
        if(coordA.SmallMove >= 240) // 长时间没有移动
        {
            coordA.SmallMove = 240;
                if(coordA.State == 1)
                    coordA.State = 2;
        }
        else  if(coordA.State == 2)
            coordA.State = 0;

        coordA.x  = coordxBuff[SaveNum];  
        coordA.y  = coordyBuff[SaveNum];       
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-9 10:38 , Processed in 0.022355 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表