📄 dm642main.c
字号:
/********************************************************************/
/* Copyright 2004 by BTECH Incorporated. */
/* All rights reserved. Property of BTECH Incorporated. */
/* Restricted rights to use, duplicate or disclose this code are */
/* granted through contract. */
/* */
/********************************************************************/
/********************************************************************/
/* 图像阈值分割 */
/********************************************************************/
#include <csl.h>
#include <csl_emifa.h>
#include <csl_i2c.h>
#include <csl_gpio.h>
#include <csl_irq.h>
#include <csl_chip.h>
#include <csl_dat.h>
#include <csl_cache.h>
#include "iic.h"
#include "vportcap.h"
#include "vportdis.h"
#include "TVP51xx.h"
#include "TVP51xx.h"
#include "evmdm642.h"
#include "saa7105.h"
#define COLOR_DISP //是否彩色显示
int portNumber;
/*图像句柄的声明*/
VP_Handle vpHchannel0;
VP_Handle vpHchannel1;
VP_Handle vpHchannel2;
/*确定图像的参数*/
const int numPixels = 720;//每行720个像素
const int numLines = 576;//每帧576行(PAL)
const int flamesize = 720*576;
/*二值化阈值初始化*/
Uint8 intThreshold = 0x80;
/*确定处理的范围*/
/*A */
/* */
/* D*/
const int intAPixels = 190;
const int intALines = 59;
const int intDPixels = 530;
const int intDLines = 229;
/*****画矩形边框函数的声明*****/
void drawRectangle();
void threshold();
extern Uint8 capChaAYSpace[720*588];
extern Uint8 capChaACbSpace[360*588];
extern Uint8 capChaACrSpace[360*588];
extern Uint8 disChaAYSpace[720*588];
extern Uint8 disChaACbSpace[360*588];
extern Uint8 disChaACrSpace[360*588];
#pragma DATA_SECTION(tmpChaAYSpace, ".external")
Uint8 tmpChaAYSpace[720*588];
#pragma DATA_SECTION(tmpChaACbSpace, ".external")
Uint8 tmpChaACbSpace[360*588];
#pragma DATA_SECTION(tmpChaACrSpace, ".external")
Uint8 tmpChaACrSpace[360*588];
/*采集与显示缓冲区的首址*/
Uint32 capYbuffer ;
Uint32 capCbbuffer ;
Uint32 capCrbuffer ;
Uint32 disYbuffer ;
Uint32 disCbbuffer ;
Uint32 disCrbuffer ;
Uint32 tempYbuffer ; //临时
Uint32 tempCbbuffer ; //临时
Uint32 tempCrbuffer ; //临时
/*图像格式标志*/
Uint8 NTSCorPAL = 0;
extern far void vectors();
extern volatile Uint32 capNewFrame;
extern volatile Uint32 disNewFrame;
/*此程序可将四个采集口的数据经过Video Port0送出*/
void main()
{
int i;
// int dp_id,dp_id2;
sysinit();
/*----------------------------------------------------------*/
capYbuffer = (Uint32)capChaAYSpace;
capCbbuffer = (Uint32)capChaACbSpace;
capCrbuffer = (Uint32)capChaACrSpace;
disYbuffer = (Uint32)disChaAYSpace;
disCbbuffer = (Uint32)disChaACbSpace;
disCrbuffer = (Uint32)disChaACrSpace;
tempYbuffer = (Uint32)tmpChaAYSpace;
tempCbbuffer = (Uint32)tmpChaACbSpace;
tempCrbuffer = (Uint32)tmpChaACrSpace;
/*----------------------------------------------------------*/
/*初始化Video Port1*/
/*将Vedio Port1设为采集输入*/
portNumber = 1;
vpHchannel1 = bt656_8bit_ncfc(portNumber);
bt656_capture_start(vpHchannel1);
/*等待第一帧数据采集完成*/
while(capNewFrame == 0){}
/*将数据存入显示缓冲区,并清采集完成的标志*/
capNewFrame =0;
for(i=0;i<numLines;i++)
{
/*传送临时Y缓冲区*/
DAT_copy((void *)(capYbuffer + i * numPixels),
(void *)(tempYbuffer + i * numPixels),
numPixels);
}
/*画边框*/
drawRectangle();
/*进行阈值分割处理*/
threshold();
for(i=0;i<0x33ae0;i++)
{
*((Uint8 *)(disCrbuffer +i)) =0x80;
*((Uint8 *)(disCbbuffer +i)) =0x80;
}
for(i=0;i<numLines;i++)
{
/*传送Y缓冲区*/
DAT_copy((void *)(tempYbuffer + i * numPixels),
(void *)(disYbuffer + i * numPixels),
numPixels);
}
/*启动显示模块*/
bt656_display_start(vpHchannel2);
/*建立显示的实时循环*/
for(;;)
{
/*当采集区的数据已经采集好,而显示缓冲区的数据已空*/
if(capNewFrame == 1)
{
/*将数据装入显示缓冲区,并清采集完成的标志*/
capNewFrame =0;
for(i=0;i<numLines;i++)
{
/*传送临时Y缓冲区*/
DAT_copy((void *)(capYbuffer + i * numPixels),
(void *)(tempYbuffer + i * numPixels),
numPixels);
DAT_wait(DAT_XFRID_WAITALL);
}
/*画边框*/
drawRectangle();
/*进行阈值分割处理*/
threshold();
}
if(disNewFrame == 1)
{ disNewFrame = 0;
for(i=0;i<numLines;i++)
{
/*传送Y缓冲区*/
DAT_copy((void *)(tempYbuffer + i * numPixels),
(void *)(disYbuffer + i * numPixels),
numPixels);
DAT_wait(DAT_XFRID_WAITALL);
}
}
}
for(;;)
{}
/*----------------------------------------------------------*/
/*采集与回放*/
}
/*画矩形边框函数的定义*/
void drawRectangle()
{
int i,j;
/*画上边*/
//奇数行
for(i=intALines-4;i<intALines;i++) //边框长度
{
for(j=intAPixels-6;j<intDPixels+6;j++) //奇数行边框宽度
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
//偶数行
for(i=numLines/2+intALines-4;i<numLines/2+intALines;i++) //边框长度
{
for(j=intAPixels-6;j<intDPixels+6;j++) //偶数行边框宽度
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
/*画下边*/
//奇数行
for(i=intDLines;i<intDLines+4;i++)//边框长度
{
for(j=intAPixels-6;j<intDPixels+6;j++) //奇数行边框宽度
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
//偶数行
for(i=numLines/2+intDLines;i<numLines/2+intDLines+4;i++)//边框长度
{
for(j=intAPixels-6;j<intDPixels+6;j++) //偶数行边框宽度
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
/*画左边*/
//奇数行
for(i=intALines;i<intDLines;i++)//边框长度
{
for(j=intAPixels-6;j<intAPixels;j++) //奇数行边框宽度
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
//偶数行
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)//边框长度
{
for(j=intAPixels-6;j<intAPixels;j++) //偶数行边框宽度
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
/*画右边*/
//奇数行
for(i=intALines;i<intDLines;i++)//边框长度
{
for(j=intDPixels;j<intDPixels+6;j++) //奇数行边框宽度
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
//偶数行
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)//边框长度
{
for(j=intDPixels;j<intDPixels+6;j++) //偶数行边框宽度
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = 0x00;
}
}
}
/*****进行阈值分割处理*********/
void threshold()
{
int i,j;
//方框内奇数行
for(i=intALines;i<intDLines;i++)//行数
{
for(j=intAPixels;j<intDPixels;j++) //像素数/每行
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = *(Uint8 *)(tempYbuffer + i*numPixels + j)<intThreshold?0x00:0xFF;
}
}
//方框内偶数行
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)//行数
{
for(j=intAPixels;j<intDPixels;j++) //像素数/每行
{
*(Uint8 *)(tempYbuffer + i*numPixels + j) = *(Uint8 *)(tempYbuffer + i*numPixels + j)<intThreshold?0x00:0xFF;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -