i am working on EVM DM6437.i am using ccsV3.3 and PAL system.
i want to do erosion ,dilation,connected component labeling using vlib2.0.
I have wrtten code for that but it's not working.i get output as whole noise and get hanged.please check my code and tell me where i am going wrong.
thanks
code file:
full code.c
/* * ======== 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> /* 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> /* BSL include files */ #include <evmdm6437.h> #include <evmdm6437_dip.h> /* Video Params Defaults */ #include <vid_params_default.h> #include<vlib.h> // this file contain all header files of other required function #include<VLIB_test.h> #include<VLIB_types.h> int p=0; uint8_t arr[414720]; int16_t runningmean1; int16_t *runningMean=&runningmean1; int16_t runningvar1; int16_t *runningVar=&runningmean1; uint32_t mask32packed[12960]; uint8_t out_data[51840]; int32_t maxbytesRequired1; int32_t *maxbytesRequired=&maxbytesRequired1; VLIB_CCHandle *handle; int32_t *numCCs; void *pBuf; uint8_t maskImage[414720]; void display(void* currentFrame); /* This example supports either PAL or NTSC depending on position of JP1 */ #define STANDARD_PAL 0 #define STANDARD_NTSC 1 #define FRAME_BUFF_CNT 6 static int read_JP1(void); static CSL_SysctlRegsOvly sysModuleRegs = (CSL_SysctlRegsOvly )CSL_SYS_0_REGS; /* * ======== main ======== */ void main() { printf("Video Preview Application\n"); fflush(stdout); /* Initialize BSL library to read jumper switches: */ EVMDM6437_DIP_init(); /* 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) { FVID_Frame *frameBuffTable[FRAME_BUFF_CNT]; FVID_Frame *frameBuffPtr; GIO_Handle hGioVpfeCcdc; GIO_Handle hGioVpbeVid0; GIO_Handle hGioVpbeVenc; int status = 0; int result; int i; int standard; int width; int height; /* Set video display/capture driver params to defaults */ PSP_VPFE_TVP5146_ConfigParams tvp5146Params = VID_PARAMS_TVP5146_DEFAULT; PSP_VPFECcdcConfigParams vpfeCcdcConfigParams = VID_PARAMS_CCDC_DEFAULT_D1; PSP_VPBEOsdConfigParams vpbeOsdConfigParams = VID_PARAMS_OSD_DEFAULT_D1; PSP_VPBEVencConfigParams vpbeVencConfigParams; standard = read_JP1(); /* Update display/capture params based on video standard (PAL/NTSC) */ if (standard == STANDARD_PAL) { width = 720; height = 576; vpbeVencConfigParams.displayStandard = PSP_VPBE_DISPLAY_PAL_INTERLACED_COMPOSITE; } else { width = 720; height = 480; vpbeVencConfigParams.displayStandard = PSP_VPBE_DISPLAY_NTSC_INTERLACED_COMPOSITE; } vpfeCcdcConfigParams.height = vpbeOsdConfigParams.height = height; vpfeCcdcConfigParams.width = vpbeOsdConfigParams.width = width; vpfeCcdcConfigParams.pitch = vpbeOsdConfigParams.pitch = width * 2; /* 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_allocBuffer(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 ( status == 0 ) { /* grab a fresh video input frame */ FVID_exchange(hGioVpfeCcdc, &frameBuffPtr); /////////user start writing code from here////////// VLIB_extractLumaFromUYUV ((frameBuffPtr->frame.frameBufferPtr), 720, 786, 576, arr); if (p==0) { VLIB_initMeanWithLumaS16 ( runningMean, arr,414720); VLIB_initVarWithConstS16 ( runningVar, 0,414720); } p++; VLIB_subtractBackgroundS16 ( mask32packed, arr, runningMean, runningVar,0x0A00,0x31ff, 414720); VLIB_updateEWRMeanS16 ( runningMean, arr, mask32packed, 0x10, 414720); VLIB_updateEWRVarianceS16 ( runningVar, runningMean,arr, mask32packed, 0x10, 414720); VLIB_erode_bin_square (((uint8_t *)mask32packed), out_data, 720, 786); VLIB_erode_bin_square ( out_data, out_data, 720, 786); VLIB_erode_bin_cross ( out_data, out_data, 720, 786); VLIB_erode_bin_cross ( out_data, out_data, 720, 786); VLIB_erode_bin_cross ( out_data, out_data, 720, 786); VLIB_erode_bin_cross ( out_data, out_data, 720, 786); VLIB_dilate_bin_square (out_data, out_data, 720, 786); VLIB_dilate_bin_square (out_data, out_data, 720, 786); VLIB_dilate_bin_cross (out_data, out_data, 720, 786); VLIB_dilate_bin_cross (out_data, out_data, 720, 786); VLIB_dilate_bin_cross (out_data, out_data, 720, 786); VLIB_calcConnectedComponentsMaxBufferSize (720, 576, 50, maxbytesRequired); pBuf = (void *)malloc(sizeof( (maxbytesRequired1))); VLIB_initConnectedComponentsList (handle,pBuf, maxbytesRequired1); VLIB_createConnectedComponentsList (handle, 720, 576, ((uint32_t *)out_data), 50, 1); VLIB_getNumCCs (handle, numCCs); printf("%d",*numCCs); VLIB_unpackMask32 (((uint32_t *)out_data), maskImage, 414720); display((frameBuffPtr->frame.frameBufferPtr)); /////////user stop writing code here////////// /* display the video frame */ FVID_exchange(hGioVpbeVid0, &frameBuffPtr); } } /* * ======== read_JP1 ======== * Read the PAL/NTSC jumper. * * Retry, as I2C sometimes fails: */ static int read_JP1(void) { int jp1 = -1; while (jp1 == -1) { jp1 = EVMDM6437_DIP_get(JP1_JUMPER); TSK_sleep(1); } return(jp1); } void display(void* currentFrame) { int xx = 0; for( xx = 0; xx < 414720; xx+=1 ) *( ( (unsigned char*)currentFrame ) + (2*xx) )=0x80; *( ( (unsigned char*)currentFrame ) + (2*xx+1) )=maskImage[xx]; }