📄 video_preview.c
字号:
/*
* Copyright 2007 by Texas Instruments Incorporated.
* All rights reserved. Property of Texas Instruments Incorporated.
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
*
* @(#) dvsdk_1_00_00_19 1_00_00_19 031507 (davinci64LC-a19x)
*/
/*
* ======== video_preview.c ========
*
*/
/* runtime include files */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
/* BIOS include files */
#include <std.h>
#include <gio.h>
#include <tsk.h>
#include <trc.h>
#include "stdio.h"
#include "evmdm6437.h"
#include "evmdm6437_led.h"
#include "evmdm6437_uart.h"
/* PSP include files */
#include <psp_i2c.h>
#include <psp_vpfe.h>
#include <psp_vpbe.h>
#include <fvid.h>
#include <psp_tvp5146_extVidDecoder.h>
/* CSL include files */
#include <soc.h>
#include <cslr_sysctl.h>
#define FRAME_BUFF_CNT 6
static CSL_SysctlRegsOvly sysModuleRegs = (CSL_SysctlRegsOvly )CSL_SYS_0_REGS;
static PSP_VPFE_TVP5146_ConfigParams tvp5146Params =
{
TRUE, /* enable656Sync */
PSP_VPFE_TVP5146_FORMAT_COMPOSITE, /* format */
PSP_VPFE_TVP5146_MODE_AUTO /* mode */
};
static PSP_VPFECcdcConfigParams vpfeCcdcConfigParams = {
PSP_VPFE_CCDC_YCBCR_8, /* dataFlow */
PSP_VPSS_FRAME_MODE, /* ffMode */
480, /* height */
720, /* width */
(720 *2), /* pitch */
0, /* horzStartPix */
0, /* vertStartPix */
NULL, /* appCallback */
{
PSP_VPFE_TVP5146_Open, /* extVD Fxn */
PSP_VPFE_TVP5146_Close,
PSP_VPFE_TVP5146_Control,
},
0 /*segId */
};
static PSP_VPBEOsdConfigParams vpbeOsdConfigParams = {
PSP_VPSS_FRAME_MODE, /* ffmode */
PSP_VPSS_BITS16, /* bitsPerPixel */
PSP_VPBE_YCbCr422, /* colorFormat */
(720 * (16/8u)), /* pitch */
0, /* leftMargin */
0, /* topMargin */
720, /* width */
480, /* height */
0, /* segId */
PSP_VPBE_ZOOM_IDENTITY, /* hScaling */
PSP_VPBE_ZOOM_IDENTITY, /* vScaling */
PSP_VPBE_EXP_IDENTITY, /* hExpansion */
PSP_VPBE_EXP_IDENTITY, /* vExpansion */
NULL /* appCallback */
};
static PSP_VPBEVencConfigParams vpbeVencConfigParams = {
PSP_VPBE_DISPLAY_NTSC_INTERLACED_COMPOSITE /* Display Standard */
};
/*
void hextodec(unsigned char* rxx,int* idec)
{
int i,mid;
int len=strlen(rxx);
for(i=0;i<len;i++)
{
if(rxx[i]>='0'&&rxx[i]<='9')
{
mid=rxx[i]-'0';
}
else if(rxx[i]>='a'&&rxx[i]<='f')
{
mid=rxx[i]-'a'+10;
}
else if(rxx[i]>='A'&&rxx[i]<='F')
{
mid=rxx[i]-'A'+10;
}
mid<<=(len-i-1)<<2;
(&idec)|=mid;
}
}
*/
/*
* ======== main ========
*/
void main() {
printf("Video Preview Application\n");
fflush(stdout);
/* Workaround to BIOS/LOG issue: SDSCM00013785 */
TRC_disable(TRC_LOGCLK);
/* VPSS PinMuxing */
/* CI10SEL - No CI[1:0] */
/* CI32SEL - No CI[3:2] */
/* CI54SEL - No CI[5:4] */
/* CI76SEL - No CI[7:6] */
/* CFLDSEL - No C_FIELD */
/* CWENSEL - No C_WEN */
/* HDVSEL - CCDC HD and VD enabled */
/* CCDCSEL - CCDC PCLK, YI[7:0] enabled */
/* AEAW - EMIFA full address mode */
/* VPBECKEN - VPBECLK enabled */
/* RGBSEL - No digital outputs */
/* CS3SEL - LCD_OE/EM_CS3 disabled */
/* CS4SEL - CS4/VSYNC enabled */
/* CS5SEL - CS5/HSYNC enabled */
/* VENCSEL - VCLK,YOUT[7:0],COUT[7:0] enabled */
/* AEM - 8bEMIF + 8bCCDC + 8 to 16bVENC */
sysModuleRegs -> PINMUX0 &= (0x005482A3u);
sysModuleRegs -> PINMUX0 |= (0x005482A3u);
/* PCIEN = 0: PINMUX1 - Bit 0 */
sysModuleRegs -> PINMUX1 &= (0xFFFFFFFEu);
sysModuleRegs -> VPSSCLKCTL = (0x18u);
return;
}
/*
* ======== video_preview ========
*/
void video_preview(void) {
PSP_VPSSSurfaceParams *frameBuffTable[FRAME_BUFF_CNT];
PSP_VPSSSurfaceParams *frameBuffPtr;
GIO_Handle hGioVpfeCcdc;
GIO_Handle hGioVpbeVid0;
GIO_Handle hGioVpbeVenc;
int status = 0;
int done = 0;
int result;
int i,k,j,kx=0,kkk=0;//*idec;
short *outBuf;
short imgdata[480][720];
int kk=0,l,tx=220,ty=400,disx=100,disy=100,m1,m2;
short w,ss,min;
short all[480][720];
UART_Handle uart0;
unsigned char rx[5],txx[1];//*rxx;
txx[0]=(unsigned char)(3);
//Open Uart Handle
uart0 = EVMDM6437_UART_open( 0, 115200 );
/* init the frame buffer table */
for (i=0; i<FRAME_BUFF_CNT; i++) {
frameBuffTable[i] = NULL;
}
/* create video input channel */
if (status == 0) {
PSP_VPFEChannelParams vpfeChannelParams;
vpfeChannelParams.id = PSP_VPFE_CCDC;
vpfeChannelParams.params = (PSP_VPFECcdcConfigParams*)&vpfeCcdcConfigParams;
hGioVpfeCcdc = FVID_create("/VPFE0",IOM_INOUT,NULL,&vpfeChannelParams,NULL);
status = (hGioVpfeCcdc == NULL ? -1 : 0);
}
/* create video output channel, plane 0 */
if (status == 0) {
PSP_VPBEChannelParams vpbeChannelParams;
vpbeChannelParams.id = PSP_VPBE_VIDEO_0;
vpbeChannelParams.params = (PSP_VPBEOsdConfigParams*)&vpbeOsdConfigParams;
hGioVpbeVid0 = FVID_create("/VPBE0",IOM_INOUT,NULL,&vpbeChannelParams,NULL);
status = (hGioVpbeVid0 == NULL ? -1 : 0);
}
/* create video output channel, venc */
if (status == 0) {
PSP_VPBEChannelParams vpbeChannelParams;
vpbeChannelParams.id = PSP_VPBE_VENC;
vpbeChannelParams.params = (PSP_VPBEVencConfigParams *)&vpbeVencConfigParams;
hGioVpbeVenc = FVID_create("/VPBE0",IOM_INOUT,NULL,&vpbeChannelParams,NULL);
status = (hGioVpbeVenc == NULL ? -1 : 0);
}
/* configure the TVP5146 video decoder */
if (status == 0) {
result = FVID_control(hGioVpfeCcdc, VPFE_ExtVD_BASE+PSP_VPSS_EXT_VIDEO_DECODER_CONFIG, &tvp5146Params);
status = (result == IOM_COMPLETED ? 0 : -1);
}
/* allocate some frame buffers */
if (status == 0) {
for (i=0; i<FRAME_BUFF_CNT && status == 0; i++) {
result = FVID_alloc(hGioVpfeCcdc, &frameBuffTable[i]);
status = (result == IOM_COMPLETED && frameBuffTable[i] != NULL ? 0 : -1);
}
}
/* prime up the video capture channel */
if (status == 0) {
FVID_queue(hGioVpfeCcdc, frameBuffTable[0]);
FVID_queue(hGioVpfeCcdc, frameBuffTable[1]);
FVID_queue(hGioVpfeCcdc, frameBuffTable[2]);
}
/* prime up the video display channel */
if (status == 0) {
FVID_queue(hGioVpbeVid0, frameBuffTable[3]);
FVID_queue(hGioVpbeVid0, frameBuffTable[4]);
FVID_queue(hGioVpbeVid0, frameBuffTable[5]);
}
/* grab first buffer from input queue */
if (status == 0) {
FVID_dequeue(hGioVpfeCcdc, &frameBuffPtr);
}
/* loop forever performing video capture and display */
while (!done && status == 0) {
/* grab a fresh video input frame */
FVID_exchange(hGioVpfeCcdc, &frameBuffPtr);
//从这里开始是我加的代码
for(i=0;i<=4;i++)
{
EVMDM6437_UART_getChar( uart0, &rx[i] );
}
if(rx[0]==1)
{
/* hextodec(rx,idec);
tx=idec[2];
ty=idec[1];
disx=idec[4];
disy=idec[3];*/
// rx[2]='10';
/* tx=atoi(&rx[2]);
// printf("result=%i\n",tx);
ty=atoi(&rx[1]);
disx=atoi(&rx[4]);
disy=atoi(&rx[3]);*/
tx=rx[2];
// printf("result=%i\n",tx);
ty=rx[1];
disx=rx[4];
disy=rx[3];
EVMDM6437_UART_putChar( uart0, txx[0] );
outBuf=frameBuffPtr->frameBufferPtr;
kx=0;
for(i = 0; i < 480; i ++)
{
for(j = 0; j < 720; j ++)
{
imgdata[i][j]=*(outBuf+kx);
kx++;
}
}
for(i = 0; i <disx; i ++)
{
for(j = 0; j <disy ; j ++)
{
all[i][j]=imgdata[tx+i][ty+j];
}
}
kkk=1;
}
if(kkk==1)
{
outBuf=frameBuffPtr->frameBufferPtr;
kx=0;
for(i = 0; i < 480; i ++)
{
for(j = 0; j < 720; j ++)
{
imgdata[i][j]=*(outBuf+kx);
kx++;
}
}
//**************************相关跟踪算法***************************//
kk=0;
for(k=tx-5;k<=tx+5;k=k+2)
{
for(l=ty-5;l<=ty+5;l=l+2)
{
ss=0;
for(i=0;i<=disx;i++)
{
for(j=0;j<=disy;j++)
{
w=all[i][j]-imgdata[k+i][l+j];
ss=abs(w)+ss;
}
}
if(kk==1)
{
if(ss<=min)
{
min=ss;
m1=k;
m2=l;
}
}
else
{
if(kk==0)
{
min=ss;
m1=k;
m2=l;
kk=kk+1;
}
}
}
}
tx=m1;
ty=m2;
// dx=m1+disx;
// dy=m2+disy;
//*************************************************************//
for(i = m1; i < m1+disx; i ++)
{
imgdata[i][m2]=-4000;
}
for(j = m2; j < m2+disy; j ++)
{
imgdata[m1+disx][j]=-4000;
}
for(i = m1; i < m1+disx; i ++)
{
imgdata[i][m2+disy]=-4000;
}
for(j = m2; j < m2+disy; j ++)
{
imgdata[m1][j]=-4000;
}
kx=0;
for(i = 0; i < 480; i ++)
{
for(j = 0; j < 720; j ++)
{
*(outBuf+kx)=imgdata[i][j];
kx++;
}
}
}
/* display the video frame */
//添加代码结束
FVID_exchange(hGioVpbeVid0, &frameBuffPtr);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -