This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

how to run Facedetect demo using USB web cam on OMAPL138LCDK

Other Parts Discussed in Thread: OMAPL138, OMAP-L138, TMS320C6748

I have OMAPL138LCDK kit i want to run the facedetect demo through USB web cam how can i do it i have the coding regarding the Facedetect demo using composite camera  which is

3404.reomapl138.zip

PLZ suggest something

  • on which part of coding in facedetect demo i need to change for interfacing a USB web cam??

  • Hi Vivek,

    Thanks for your post.

    The foremost criteria is that, you need to ensure your USB web cam supports composite video/image capture to run face detect demo on omapl138 lcdk. Usually, the input would be captured with the standard Composite camera in the form of YUV images at 30fps. The demo supports D1 SD resolution (720*480) image for real time video capture.

    Actually, face detect demonstration comes with the C6748 BIOS C6 SDK with the source code of the projects and you should ensure the connectivity of your USB web cam. composite input at the J9 on composite video input port.

    To start with, please refer below the wiki resources:

    http://processors.wiki.ti.com/index.php/L138/C6748_Development_Kit_(LCDK)#Face_Detection_Demonstartion

    To run the demo on c6748 LCDK, please refer the BIOS C6SDK Getting started guide as below:

    http://processors.wiki.ti.com/index.php/BIOS_C6SDK_2.0_Getting_Started_Guide#Running_the_Demonstration_Application

    To ensure the hardware setup for facedetect demo on LCDK, please refer the below BIOS C6SDK user guide wiki and to run the demo:

    http://processors.wiki.ti.com/index.php/BIOS_C6SDK_2.0_User_Guide#Face_Detect_Demo

    Thanks & regards,

    Sivaraj K

    -------------------------------------------------------------------------------------------------------
    Please click the Verify Answer button on this post if it answers your question.
    -------------------------------------------------------------------------------------------------------
  • sir

    i cant get on these following line

    Actually, face detect demonstration comes with the C6748 BIOS C6 SDK with the source code of the projects and you should ensure the connectivity of your USB web cam. composite input at the J9 on composite video input port.


    i m not getting u here u mentioned both a USB web cam input and the input from J9 on composite video input port..

    sir i want to use USB web cam

    and from the above these 2 lines u said the video stream should be of resolution 720*480. i am using logitech c270 web cam which has  following features

    VIDEO AND IMAGE
    Frame Rate 30 fps
    Still Image Sensor Resolution 3 megapixel
    Is HD Yes
    Sensor Type HD
    Video Capture Resolution 1280 x 720

    can running face detect with above camera is possible or not?

  • Hi Vivek,

    Thanks for your post.

    Basically, if you walkthrough the face detect source code, it expect an image input with minimum resolution of 720*480, so, if your image file is ready with any composite input source at J9 video input port on OMAPL138 LCDK board, then the face detect source code would take care in the colorconvertTask() function by allocating & initializing the image captured thru. the composite video source.

    Please review the source code attached

    /*
     * facedetect_lcdk.c
     *
     * This file contains face detection demo code for LCDK.
     *
     * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
     *
     *
     *  Redistribution and use in source and binary forms, with or without
     *  modification, are permitted provided that the following conditions
     *  are met:
     *
     *    Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     *    Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the
     *    distribution.
     *
     *    Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    
    /**
     *  \file   facedetect_lcdk.c
     *
     *  \brief  This file contains the face detection demo code for LCDK.
     *
     *          This application captures the live camera input which is then
     * 			passed to the DSP. The DSP runs the face detection algorithm
     * 			provided by OpenCV and draws a rectangular box around the
     * 			detected face. The output is displayed over LCDC.
     *
     */
    
    /* ========================================================================== */
    /*                          INCLUDE FILES                                     */
    /* ========================================================================== */
    #include <xdc/std.h>
    #include <xdc/runtime/Error.h>
    #include <xdc/runtime/System.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Semaphore.h>
    #include <ti/sysbios/family/c64p/Hwi.h>
    
    #include <stdio.h>
    #include "psc.h"
    #include "vpif.h"
    #include "raster.h"
    #include "interrupt.h"
    #include "lcdkC6748.h"
    #include "soc_C6748.h"
    #include "hw_psc_C6748.h"
    #include "adv7343.h"
    #include "tvp5147.h"
    #include "cdce913.h"
    #include "codecif.h"
    #include "i2cgpio.h"
    #include "cv.h"
    #include "cxtypes.h"
    #include "string.h"
    #include "facedetect.h"
    
    /******************************************************************************
    **                      INTERNAL MACROS
    *******************************************************************************/
    #define MSTPRI1									(0x01C14114)
    #define MSTPRI2									(0x01C14118)
    
    #define CAPTURE_IMAGE_WIDTH					 	(720)
    #define CAPTURE_IMAGE_HEIGHT				 	(488)
    #define DISPLAY_IMAGE_WIDTH						(640)
    #define DISPLAY_IMAGE_HEIGHT					(480)
    #define CLASSIFIER_CASCADE_SIZE      			(52519)
    #define REFERENCE_LOCATION_1         			(0xC30011B0)
    #define REFERENCE_LOCATION_2		 			(0xC303464B)
    #define CV_DEFAULT_IMAGE_ROW_ALIGN   			(8)
    
    #define I2C_SLAVE_CODEC_ADV7343                 (0x2Au)
    #define I2C_SLAVE_CODEC_TVP5147_1_SVIDEO    	(0x5Cu)
    #define I2C_SLAVE_CODEC_TVP5147_2_COMPOSITE    	(0x5Du)
    #define I2C_SLAVE_CDCE913      					(0x65u)
    #define I2C_SLAVE_UI_EXPANDER	      			(0x20u)
    
    #define INT_CHANNEL_I2C                       	(0x2u)
    
    #define OFFSET1									((CAPTURE_IMAGE_HEIGHT - DISPLAY_IMAGE_HEIGHT)/2)
    #define OFFSET2									((CAPTURE_IMAGE_WIDTH - DISPLAY_IMAGE_WIDTH)/2)
    #define OFFSET 									(CAPTURE_IMAGE_WIDTH * OFFSET1 + OFFSET2)
    
    /******************************************************************************
    **                      GLOBAL FUNCTION PROTOTYPES
    *******************************************************************************/
    extern void cbcr422sp_to_rgb565_c(const unsigned char * restrict, unsigned int,
    		unsigned int, const short*, const unsigned char *restrict,
    		unsigned int, unsigned short *restrict, unsigned int, unsigned);
    
    /******************************************************************************
    **                      INTERNAL FUNCTION PROTOTYPES
    *******************************************************************************/
    static void SetUpVPIFRx(void);
    static void SetUpLCD(void);
    Void VPIFIsr(UArg arg);
    Void LCDIsr(UArg arg);
    
    Void colorconvertTask(UArg arg0, UArg arg1);
    Void facedetectTask(UArg arg0, UArg arg1);
    Void clockHandler(UArg arg);
    
    /******************************************************************************
    **                      INTERNAL VARIABLE DEFINITIONS
    *******************************************************************************/
    unsigned int            pingpong=1, buffcount=0, buffcount2, display_buff_1=0;
    int 					facedetect_complete=1, buffer_ready=0;
    volatile unsigned int   changed=1, updated=3, processed=1;
    unsigned char 			*buff_luma[2], *buff_chroma[2];
    unsigned char			buff_luma1[CAPTURE_IMAGE_WIDTH * CAPTURE_IMAGE_HEIGHT];
    unsigned char			buff_luma2[CAPTURE_IMAGE_WIDTH * CAPTURE_IMAGE_HEIGHT];
    unsigned char			buff_chroma1[CAPTURE_IMAGE_WIDTH * CAPTURE_IMAGE_HEIGHT];
    unsigned char			buff_chroma2[CAPTURE_IMAGE_WIDTH * CAPTURE_IMAGE_HEIGHT];
    unsigned char			proc_buff_luma[DISPLAY_IMAGE_WIDTH * DISPLAY_IMAGE_HEIGHT];
    unsigned char           *videoTopY, *videoTopC, *proc_buff_ptr;
    unsigned short          *videoTopRgb1, *videoTopRgb2;
    unsigned short          Rgb_buffer1[DISPLAY_IMAGE_WIDTH*DISPLAY_IMAGE_HEIGHT + 16];
    unsigned short			Rgb_buffer2[DISPLAY_IMAGE_WIDTH*DISPLAY_IMAGE_HEIGHT + 16];
    const short             ccCoeff[5] = {0x2000, 0x2BDD, -0x0AC5, -0x1658, 0x3770};
    
    CvHaarClassifierCascade 	*cascade;
    IplImage 					*image=NULL, *image1=NULL;
    CvMemStorage 				*storage;
    CvSeq 						*dsp_sequence = NULL, *dsp_sequence2 = NULL;
    CvScalar 	  				blue = {255, 0, 0, 0};
    CvPoint 					c1, c2;
    CvRect 						*r;
    
    Semaphore_Handle 			sem1;
    Semaphore_Handle 			sem2;
    
    /******************************************************************************
    **                       FUNCTION DEFINITIONS
    *******************************************************************************/
    Void main()
    {
    	Hwi_Params 		params;
    	Hwi_Handle 		Hwi1, Hwi2;
    	Task_Params 	taskParams;
    	Task_Handle 	task1, task2;
    	Clock_Params 	clockParams;
    	Clock_Handle 	Clk;
    	Error_Block 	eb;
    
        /* Create a Semaphore object to be use as a resource lock */
        sem1 = Semaphore_create(0, NULL, NULL);
        sem2 = Semaphore_create(0, NULL, NULL);
    
    	/* Create the Color Convert Task */
        Error_init(&eb);
    	Task_Params_init(&taskParams);
    	taskParams.priority = 1;
    	taskParams.stackSize = 10000;
    	task1 = Task_create(colorconvertTask, &taskParams, &eb);
    	if (task1 == NULL)
    	{
    		System_printf("Task_create() failed for Color Conversion!\n");
    		BIOS_exit(0);
    	}
    
    	/* Create the FaceDetect Task*/
    	task2 = Task_create(facedetectTask, &taskParams, &eb);
    	if (task2 == NULL)
    	{
    		System_printf("Task_create() failed for Face Detection!\n");
    		BIOS_exit(0);
    	}
    
    	/* Create the VPIF Interrupt*/
    	Hwi_Params_init(&params);
    	params.eventId = 95;
    	params.enableInt = FALSE;
    	Hwi1 = Hwi_create(8, &VPIFIsr, &params, &eb);
    	if (Hwi1 == NULL)
    	{
    		System_printf("Hwi_create() failed for VPIF!\n");
    		BIOS_exit(0);
    	}
    
    	/* Create the LCDC Interrupt*/
    	Hwi_Params_init(&params);
    	params.eventId = 73;
    	params.enableInt = FALSE;
    	Hwi2 = Hwi_create(9, &LCDIsr, &params, &eb);
    	if (Hwi2 == NULL)
    	{
    		System_printf("Hwi_create() failed for LCDC!\n");
    		BIOS_exit(0);
    	}
    
    	/* Create a clock that would go off every 1 Clock tick*/
    	Clock_Params_init(&clockParams);
    	clockParams.period = 1;
    	clockParams.startFlag = TRUE;
    	Clk = Clock_create((Clock_FuncPtr)clockHandler, 4, &clockParams, &eb);
    	if (Clk == NULL) {
    	System_abort("Clock0 create failed");
    	}
    
    	/* Setting the Master priority for LCD DMA controller to highest level */
    	*((volatile uint32_t *) MSTPRI2) = *((volatile uint32_t *) MSTPRI2) & 0x0FFFFFFF;
    
    	BIOS_start(); /* enable interrupts and start SYS/BIOS */
    }
    
    /*
    ** ClockHandler
    */
    Void clockHandler(UArg arg)
    {
    	/* Call Task_yield every 1 ms */
    	Task_yield();
    }
    
    /*
    ** ColorconvertTask - This would color convert the captured frames and make it available for the LCDC display.
    ** Also, if the facedetect algorithm has finished working on the frame provided, it would provide a new frame.
    */
    Void colorconvertTask(UArg a0, UArg a1)
    {
    	int   i, *buffer;
    
    	/* Allocate and initialize 'image' which would then be passed to the face detection algorithm */
    	image = (IplImage *) cvAlloc(sizeof(*image));
    	cvInitImageHeader(image, cvSize(DISPLAY_IMAGE_WIDTH, DISPLAY_IMAGE_HEIGHT), IPL_DEPTH_8U, 1,
    			IPL_ORIGIN_TL, CV_DEFAULT_IMAGE_ROW_ALIGN);
    
    	/* Allocate and initialize 'image1' which would then be used to draw a box on the output buffer */
    	image1 = (IplImage *) cvAlloc(sizeof(*image1));
    	cvInitImageHeader(image1, cvSize(DISPLAY_IMAGE_WIDTH, DISPLAY_IMAGE_HEIGHT), IPL_DEPTH_16U,
    			1, IPL_ORIGIN_TL, CV_DEFAULT_IMAGE_ROW_ALIGN);
    
    	/* Initialize the cascade buffer */
    	buffer = (int *) cvAlloc(sizeof(cascade_buffer));
    	cascade = (CvHaarClassifierCascade *) buffer;
    
    	for (i = 0; i < CLASSIFIER_CASCADE_SIZE; i++)
    	{
    		if (cascade_buffer[i] > REFERENCE_LOCATION_1 && cascade_buffer[i] < REFERENCE_LOCATION_2)
    			*(buffer + i) = (cascade_buffer[i] - REFERENCE_LOCATION_1) + (int) cascade;
    		else
    			*(buffer + i) = cascade_buffer[i];
    	}
    
    	/* Initialize the dsp_sequnce which would contain the face coordinates */
    	dsp_sequence2 = (CvSeq *) cvAlloc(sizeof(CvSeq) * 2);
    	memset(dsp_sequence2, 0, sizeof(CvSeq) * 2);
    
    	/* Allocate pointers to buffers */
    	buff_luma[0] = buff_luma1;
    	buff_luma[1] = buff_luma2;
    	buff_chroma[0] = buff_chroma1;
    	buff_chroma[1] = buff_chroma2;
    	proc_buff_ptr = proc_buff_luma;
    
    	/* Initializing palette for first buffer */
    	*Rgb_buffer1 = 0x4000;
    	for (i = 1; i < 16; i++)
    		*(Rgb_buffer1 +i) = 0x0000;
    	videoTopRgb1 = Rgb_buffer1 + i;
    
    	/* Initializing palette for second buffer */
    	*Rgb_buffer2 = 0x4000;
    	for (i = 1; i < 16; i++)
    		*(Rgb_buffer2 + i) = 0x0000;
    	videoTopRgb2 = Rgb_buffer2 + i;
    
    	/* Power on VPIF */
    	PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_VPIF, PSC_POWERDOMAIN_ALWAYS_ON,
    			PSC_MDCTL_NEXT_ENABLE);
    
    	/* Initialize I2C and program UI GPIO expander, TVP5147, and ADV7343 via I2C */
    	I2CPinMuxSetup(0);
    
    	/*Initialize the TVP5147 to accept composite video */
    	I2CCodecIfInit(SOC_I2C_0_REGS, INT_CHANNEL_I2C,
    			I2C_SLAVE_CODEC_TVP5147_2_COMPOSITE);
    	TVP5147CompositeInit(SOC_I2C_0_REGS);
    
    	/* Setup VPIF pinmux */
    	VPIFPinMuxSetup();
    
    	/* Setup LCD */
    	SetUpLCD();
    
    	/* Initialize VPIF */
    	SetUpVPIFRx();
    	VPIFDMARequestSizeConfig(SOC_VPIF_0_REGS, VPIF_REQSIZE_ONE_TWENTY_EIGHT);
    	VPIFEmulationControlSet(SOC_VPIF_0_REGS, VPIF_HALT);
    
    	/* Initialize buffer addresses for 1st frame*/
    	VPIFCaptureFBConfig(SOC_VPIF_0_REGS, VPIF_CHANNEL_0, VPIF_TOP_FIELD,
    			VPIF_LUMA, (unsigned int) buff_luma[0], CAPTURE_IMAGE_WIDTH*2);
    	VPIFCaptureFBConfig(SOC_VPIF_0_REGS, VPIF_CHANNEL_0, VPIF_TOP_FIELD,
    			VPIF_CHROMA, (unsigned int) buff_chroma[0], CAPTURE_IMAGE_WIDTH*2);
    	VPIFCaptureFBConfig(SOC_VPIF_0_REGS, VPIF_CHANNEL_0, VPIF_BOTTOM_FIELD,
    			VPIF_LUMA, (unsigned int) (buff_luma[0] + CAPTURE_IMAGE_WIDTH), CAPTURE_IMAGE_WIDTH*2);
    	VPIFCaptureFBConfig(SOC_VPIF_0_REGS, VPIF_CHANNEL_0, VPIF_BOTTOM_FIELD,
    			VPIF_CHROMA, (unsigned int) (buff_chroma[0] + CAPTURE_IMAGE_WIDTH), CAPTURE_IMAGE_WIDTH*2);
    
    	/* Configuring the base ceiling */
    	RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int) Rgb_buffer2,
    			(unsigned int) (Rgb_buffer2 + DISPLAY_IMAGE_WIDTH * DISPLAY_IMAGE_HEIGHT + 15), 0);
    	RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int) Rgb_buffer2,
    			(unsigned int) (Rgb_buffer2 + DISPLAY_IMAGE_WIDTH * DISPLAY_IMAGE_HEIGHT + 15), 1);
    
    	/* Enable interrupts */
    	Hwi_enable();
    	Hwi_enableInterrupt(8);
    	Hwi_enableInterrupt(9);
    
    	/* Enable capture */
    	VPIFCaptureChanenEnable(SOC_VPIF_0_REGS, VPIF_CHANNEL_0);
    
    	/* Enable VPIF interrupt */
    	VPIFInterruptEnable(SOC_VPIF_0_REGS, VPIF_FRAMEINT_CH0);
    	VPIFInterruptEnableSet(SOC_VPIF_0_REGS, VPIF_FRAMEINT_CH0);
    
    	/* Enable End of frame interrupt */
    	RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS);
    
    	/* Enable raster */
    	RasterEnable(SOC_LCDC_0_REGS);
    
    	buffcount++;
    	buffcount2 = buffcount - 1;
    
    	/* Run forever */
    	while (1)
    	{
    		/* Wait here till a new frame is not captured */
    		Semaphore_pend(sem1, BIOS_WAIT_FOREVER);
    
    		/* Process the next buffer only when both the raster buffers
    		 * are pointing to the current buffer to avoid jitter effect
    		 */
    		Semaphore_pend(sem2, BIOS_WAIT_FOREVER);
    		processed = 0;
    		changed = 0;
    		updated = 0;
    
    		/* Copy the current frame into another buffer for running the facedetect algorithm */
    		if(facedetect_complete)
    		{
    			facedetect_complete=0;
    			for(i=0;i<DISPLAY_IMAGE_HEIGHT;i++)
    				memcpy((proc_buff_ptr + i*DISPLAY_IMAGE_WIDTH),(videoTopY + OFFSET +i*CAPTURE_IMAGE_WIDTH),
    						DISPLAY_IMAGE_WIDTH);
    			image->imageData = (char *)proc_buff_ptr;
    			buffer_ready=1;
    		}
    
    	    /* Convert the buffer from CBCR422 semi-planar to RGB565,
    	     *  Set the flag for the buffer to be displayed on the LCD (which would be the processed buffer)
    	     *  and notify the LCD of availability of a processed buffer.
    	     *  The output buffers are ping-ponged each time.
    	     */
    		if (pingpong)
    		{
    			cbcr422sp_to_rgb565_c(
    					(const unsigned char *) (videoTopC + OFFSET),
    					DISPLAY_IMAGE_HEIGHT, CAPTURE_IMAGE_WIDTH, ccCoeff,
    					(const unsigned char *) (videoTopY + OFFSET),
    					CAPTURE_IMAGE_WIDTH, videoTopRgb1, DISPLAY_IMAGE_WIDTH,
    					DISPLAY_IMAGE_WIDTH);
    			display_buff_1 = 1;
    		}
    		else
    		{
    			cbcr422sp_to_rgb565_c(
    					(const unsigned char *) (videoTopC + OFFSET),
    					DISPLAY_IMAGE_HEIGHT, CAPTURE_IMAGE_WIDTH, ccCoeff,
    					(const unsigned char *) (videoTopY + OFFSET),
    					CAPTURE_IMAGE_WIDTH, videoTopRgb2, DISPLAY_IMAGE_WIDTH,
    					DISPLAY_IMAGE_WIDTH);
    			display_buff_1 = 0;
    		}
    		pingpong = !pingpong;
    		processed = 1;
    		changed = 1;
    	}
    }
    
    /*
    ** FacedetectTask - Runs the Face Detection Algorithm on the frame provided to it
    */
    Void facedetectTask(UArg a0, UArg a1)
    {
    	int i;
    	while(1)
    	{
    		while(!buffer_ready)
    			Task_sleep(10);
    		buffer_ready=0;
    
    		storage = cvCreateMemStorage(0);
    
    		/* Apply OpenCV haardetect algorithm */
    		dsp_sequence = cvHaarDetectObjects(image, cascade, storage, 2.5, 2, 0, cvSize(30, 30));
    
    		/* Make a copy of the detected sequence to draw it on each frame */
    		for (i = 0; i < 2; i++)
    			*(dsp_sequence2 + i) = *(dsp_sequence + i);
    
    		cvReleaseMemStorage(&storage);
    
    		facedetect_complete=1;
    	}
    }
    
    /*
     * Initialize capture
     */
    static void SetUpVPIFRx(void)
    {
    	/* Disable interrupts */
    	VPIFInterruptDisable(SOC_VPIF_0_REGS, VPIF_FRAMEINT_CH1);
    	VPIFInterruptDisable(SOC_VPIF_0_REGS, VPIF_FRAMEINT_CH0);
    
    	/* Disable capture ports */
    	VPIFCaptureChanenDisable(SOC_VPIF_0_REGS, VPIF_CHANNEL_1);
    	VPIFCaptureChanenDisable(SOC_VPIF_0_REGS, VPIF_CHANNEL_0);
    
    	/* Interrupt after capturing the bottom field of every frame */
    	VPIFCaptureIntframeConfig(SOC_VPIF_0_REGS, VPIF_CHANNEL_0, VPIF_FRAME_INTERRUPT_BOTTOM);
    
    	/* Y/C interleaved capture over 8-bit bus */
    	VPIFCaptureYcmuxModeSelect(SOC_VPIF_0_REGS, VPIF_CHANNEL_0, VPIF_YC_MUXED);
    
    	/* Capturing 480I (SD NTSC) */
    	VPIFCaptureModeConfig(SOC_VPIF_0_REGS, VPIF_480I, VPIF_CHANNEL_0, 0, (struct vbufParam *) 0);
    }
    
    /*
     * Configures raster to display image
     */
    static void SetUpLCD(void)
    {
        PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_LCDC, PSC_POWERDOMAIN_ALWAYS_ON,
    		     PSC_MDCTL_NEXT_ENABLE);
    
        LCDPinMuxSetup();
    
        /* disable raster */
        RasterDisable(SOC_LCDC_0_REGS);
    
        /* configure the pclk */
        RasterClkConfig(SOC_LCDC_0_REGS, 25000000, 150000000);
    
        /* configuring DMA of LCD controller */
        RasterDMAConfig(SOC_LCDC_0_REGS, RASTER_DOUBLE_FRAME_BUFFER,
                        RASTER_BURST_SIZE_16, RASTER_FIFO_THRESHOLD_8,
                        RASTER_BIG_ENDIAN_DISABLE);
    
        /* configuring modes(ex:tft or stn,color or monochrome etc) for raster controller */
        RasterModeConfig(SOC_LCDC_0_REGS, RASTER_DISPLAY_MODE_TFT,
                         RASTER_PALETTE_DATA, RASTER_COLOR, RASTER_RIGHT_ALIGNED);
    
        /* frame buffer data is ordered from least to Most significant bye */
        RasterLSBDataOrderSelect(SOC_LCDC_0_REGS);
    
        /* disable nibble mode */
        RasterNibbleModeDisable(SOC_LCDC_0_REGS);
    
         /* configuring the polarity of timing parameters of raster controller */
        RasterTiming2Configure(SOC_LCDC_0_REGS, RASTER_FRAME_CLOCK_LOW |
                                                RASTER_LINE_CLOCK_LOW  |
                                                RASTER_PIXEL_CLOCK_LOW |
                                                RASTER_SYNC_EDGE_RISING|
                                                RASTER_SYNC_CTRL_ACTIVE|
                                                RASTER_AC_BIAS_HIGH     , 0, 255);
    
        /* configuring horizontal timing parameter */
       RasterHparamConfig(SOC_LCDC_0_REGS, DISPLAY_IMAGE_WIDTH, 64, 48, 48);
    
        /* configuring vertical timing parameters */
       RasterVparamConfig(SOC_LCDC_0_REGS, DISPLAY_IMAGE_HEIGHT, 2, 11, 31);
    
       /* configuring fifo delay to */
       RasterFIFODMADelayConfig(SOC_LCDC_0_REGS, 2);
    }
    
    /*
    ** VPIF Interrupt service routine.
    */
    Void VPIFIsr(UArg arg)
    {
    #ifdef _TMS320C6X
    	IntEventClear(SYS_INT_VPIF_INT);
    #endif
    
    	/* If previously captured frame is not processed, clear this interrupt and return */
    	if (!processed)
    	{
    		VPIFInterruptStatusClear(SOC_VPIF_0_REGS, VPIF_FRAMEINT_CH0);
    		return;
    	}
    
    	/* buffcount represents buffer to be given to capture driver and
    	 * buffcount2 represents the newly captured buffer to be processed
    	 */
    	processed = 0;
    	buffcount++;
    	buffcount2 = buffcount - 1;
    	// Currently only two buffers are being used for capture
    	if (buffcount == 2)
    		buffcount = 0;
    
    	/* Initialize buffer addresses for a new frame*/
    	VPIFCaptureFBConfig(SOC_VPIF_0_REGS, VPIF_CHANNEL_0, VPIF_TOP_FIELD,
    			VPIF_LUMA, (unsigned int) buff_luma[buffcount], CAPTURE_IMAGE_WIDTH*2);
    	VPIFCaptureFBConfig(SOC_VPIF_0_REGS, VPIF_CHANNEL_0, VPIF_TOP_FIELD,
    			VPIF_CHROMA, (unsigned int) buff_chroma[buffcount], CAPTURE_IMAGE_WIDTH*2);
    	VPIFCaptureFBConfig(SOC_VPIF_0_REGS, VPIF_CHANNEL_0, VPIF_BOTTOM_FIELD,
    			VPIF_LUMA, (unsigned int) (buff_luma[buffcount] + CAPTURE_IMAGE_WIDTH), CAPTURE_IMAGE_WIDTH*2);
    	VPIFCaptureFBConfig(SOC_VPIF_0_REGS, VPIF_CHANNEL_0, VPIF_BOTTOM_FIELD,
    			VPIF_CHROMA, (unsigned int) (buff_chroma[buffcount] + CAPTURE_IMAGE_WIDTH), CAPTURE_IMAGE_WIDTH*2);
    
    	/* Initialize buffer addresses with the captured frame ready to be processed */
    	videoTopC = buff_chroma[buffcount2];
    	videoTopY = buff_luma[buffcount2];
    
    	/* clear interrupt */
    	VPIFInterruptStatusClear(SOC_VPIF_0_REGS, VPIF_FRAMEINT_CH0);
    
    	Semaphore_post(sem1);
    }
    
    /*
    ** For each end of frame interrupt base and ceiling is reconfigured
    */
    Void LCDIsr(UArg arg)
    {
    	unsigned int i, status;
    #ifdef _TMS320C6X
    	IntEventClear(SYS_INT_LCDC_INT);
    #endif
    
    	/* Find which interrupt occurred and clear it */
    	status = RasterIntStatus(SOC_LCDC_0_REGS,
    			RASTER_END_OF_FRAME0_INT_STAT | RASTER_END_OF_FRAME1_INT_STAT);
    	status = RasterClearGetIntStatus(SOC_LCDC_0_REGS, status);
    
    	if(!changed)
    		return;
    
    	/* Draw a rectangle from the detected sequence onto the current frame*/
    	if (dsp_sequence2 == NULL);
    	else
    	{
    		if (display_buff_1)
    			image1->imageData = (char *)videoTopRgb1;
    		else
    			image1->imageData = (char *)videoTopRgb2;
    		//printf("DSP sequence contains %i elements:\n", dsp_sequence2->total);
    		for (i = 0; i < dsp_sequence2->total; i++)
    		{
    			r = (CvRect *) cvGetSeqElem(dsp_sequence2, i);
    			//printf("%4i: %4i, %4i (%ix%i)\n", i, r->x, r->y, r->width, r->height);
    
    			// mark with thick blue rectangle
    			c1.x = r->x;
    			c1.y = r->y;
    			c2.x = r->x + r->width;
    			c2.y = r->y + r->height;
    			cvRectangle(image1, c1, c2, blue, 2, 8, 0);
    		}
    	}
    
    	/* Display the appropriate output buffer on the appropriate raster buffer
    	 * and if a new processed buffer is available, let the DSP know that
    	 * it has configured the raster buffer to point to the new output buffer
    	 * by updating the 'updated' flag
    	 */
    	if (display_buff_1)
    	{
    		if (status & RASTER_END_OF_FRAME0_INT_STAT)
    		{
    			RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int) Rgb_buffer1,
    					(unsigned int) (Rgb_buffer1 + DISPLAY_IMAGE_WIDTH * DISPLAY_IMAGE_HEIGHT + 15), 0);
    				updated = updated | 0x1;
    		}
    		if (status & RASTER_END_OF_FRAME1_INT_STAT)
    		{
    			RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int) Rgb_buffer1,
    					(unsigned int) (Rgb_buffer1 + DISPLAY_IMAGE_WIDTH * DISPLAY_IMAGE_HEIGHT + 15), 1);
    				updated = updated | 0x2;
    		}
    	}
    	else
    	{
    		if (status & RASTER_END_OF_FRAME0_INT_STAT)
    		{
    			RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int) Rgb_buffer2,
    					(unsigned int) (Rgb_buffer2 + DISPLAY_IMAGE_WIDTH * DISPLAY_IMAGE_HEIGHT + 15), 0);
    				updated = updated | 0x1;
    		}
    		if (status & RASTER_END_OF_FRAME1_INT_STAT)
    		{
    			RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int) Rgb_buffer2,
    					(unsigned int) (Rgb_buffer2 + DISPLAY_IMAGE_WIDTH * DISPLAY_IMAGE_HEIGHT + 15), 1);
    				updated = updated | 0x2;
    		}
    	}
    
    	if(updated==3)
    	{
    		changed=0;
    		Semaphore_post(sem2);
    	}
    }
    
    /***************************** End Of File ************************************/
    

    I think, the above mentioned web cam. video specification are fine to run face detect demo.

    Thanks & regards,

    Sivaraj K

    -------------------------------------------------------------------------------------------------------
    Please click the Verify Answer button on this post if it answers your question.
    -------------------------------------------------------------------------------------------------------
  • sir

    you mentioned

    if your image file is ready with any composite input source at J9 video input port on OMAPL138 LCDK board, 

    if i will use a USB web cam then it will be connected to J5 port which is Usb host .J9 port uses different  camera not USB camera .

    now i want to know that the  colorconvertTask() function will automatically able to take the input from USB cam which will be connected to J5 port of LCDK board or not?

      

  • Hi Vivek,

    Thanks for your update.

    Yes it does. Please walk through the colorconvertTask() function in the facedetect source code. You will understand how the code is written.

    Thanks & regards,

    Sivaraj K

    -------------------------------------------------------------------------------------------------------
    Please click the Verify Answer button on this post if it answers your question.
    -------------------------------------------------------------------------------------------------------
  • Sir

    i have tried below procedure but unable to run the facedetect demo through the USB cam

    followed the links which are

     http://processors.wiki.ti.com/index.php/BIOS_C6SDK_2.0_User_Guide#Face_Detect_Demo

    http://processors.wiki.ti.com/index.php/BIOS_C6SDK_2.0_Getting_Started_Guide#Running_the_Demonstration_Application

     How to Flash Face detect demo on C6748 LCDK

    The procedure is similar to flashing on the EVM except using different config file and hardware changes. To avoild confusion, we'll go through the procedure again.

    At first, you need to create the AIS version of facedetect_lcdk.out and then the AIS file is flashed using the OMAP-L138 FlashAndBootUtlis. 

    NOTE - The demo can be flashed only on C6748 stand alone core amd not on the one available in OMAPL138. 
    You can skip STEP 1 by using the AIS output file (facedetect_lcdk.bin) provided in c6sdk folder -> demos -> flash -> lcdk

    STEP 1:

    • Install the AISgen tool from the setup available in tools subfolder of the c6sdk folder
    • Open 'AISgen for D800K008' and go to File -> Load Configuration
    • Browse to c6sdk_02_00_00_00\demos\flash\lcdk and open LCDK_AISGen_Config.cfg
    • Choose the DSP Application File which in our case would be facedetect_lcdk.out found at c6sdk_02_00_00_00\demos\facedetect\bin\{COMPILATION_METHOD}\lcdk\Release
    • Choose where you want to create the AIS output file, say C:\ and provide a name for that file, say facedetect_lcdk.bin i.e. C:\facedetect_lcdk.bin
    • Now hit Generate AIS. In a few seconds, facedetect_lcdk.bin must be created in C:\. You may now close the AISgen tool.

     STEP 2:

    • Connect a mini USB cable at J3 on the UART port with the other end going to the host computer at one of its USB ports.
    • Unplug the power cable from the board.
    • Turn DIP switches 2 and 4 to ON position while others remain in the OFF position.
    • To ensure you have selected the UART boot mode open a serial port terminal like Tera Term, set the baud rate to 115200 and turn ON the EVM. You should see a message called BOOT ME on the terminal each time you turn on the EVM. Now close your serial port terminal to flash the image on the chip.
    • Find the COM Port Number being used by your PC. It can be found by going to Device Manager -> Ports or when you run Tera Term, it shows the Serial port available for connection which is the COM Port.
    • Open cmd.exe on your PC
    • cd to <BIOS-C6SDK INSTALL DIR>c6sdk_02_00_00_00\tools\OMAP-L138_FlashAndBootUtils_2_36\OMAP-L138\GNU
    • If there is an image flashed already, run the following command to erase it
    sfh_OMAP-L138.exe -erase -targetType C6748_LCDK -flashType NAND -p <COM_Port_Number> 

    where COM_Port_Number is the serial port being used say COM4

    • Run the following command
    sfh_OMAP-L138.exe -flash_noubl -targetType C6748_LCDK -flashType NAND -p <COM_Port_Number> "<Ais_File_Name>" 

    where COM_Port_Number is the serial port being used say COM4 and Ais_File_Name is the file generated by AISgen tool, in our case C:\facedetect_lcdk.bin

    • Now the utility waits for a BOOT ME message from the chip. So turn ON the LCDK or if its already ON, reset it. Once the BOOT ME message is received, the utility will start flashing to the LCDK.
    • Wait till the flashing is complete. The command window will look as below 

    Flash2.png

    • Turn OFF the LCDK by unplugging the power cord and turn switches 2,3 and 4 to ON while others remain in the OFF position.
    • Turn ON the LCDK and wait for around 10 seconds. If the hardware is setup correctly, you should see the demo working as expected.

    After following all the procedure i am unable to get the selection option on teraterm and also on LCD no output is there..

    i have used usb web cam which is 

    iBall Face2Face C8.0 Webcam features are

    VIDEO AND IMAGE
    Video Sensor Resolution 4 megapixel
    Frame Rate 30 fps
    Still Image Sensor Resolution 8 megapixel
    Is HD No
    Sensor Type CMOS
    Video Capture Resolution 2304 x 1728
    Image Capture Resolution 3264 x 2448

    plz help to run the demo through web cam. i have tried two time by changing web cam also but it does't worked

  • Hi Vivek,

    As Mr.Sivaraj suggested,

    Have you gone through facedetect code & understood the concepts which TI developers implemented?

    I am suggesting to do that modify your code in CCS and debug in CCS itself (through loading gel files and Load options) instead of flashing images without testing those binaries.

    1. Ensure that the Hardware is setup as explained in Hardware Setup for Demos in User Guide.
    2. Open CCSv5.1 and launch the target configuration file for TMS320C6748 or OMAPL138
    3. Go to Tools -> GEL Files 
    4. Right click inside the GEL Files window and select Load GEL.
    5. Browse to the pdk_C6748 folder -> gel and select C6748.gel
    6. The loaded gel file will be in GEL Files window. 
    7. In the Debug window, Right click on "Spectrum Digital XDS510USB Emulator_0/C674X_0 [Non-Project Debug Session]" -> Connect Target (Make sure the EVMC6748/LCDK is ON before saying Connect Target)
    8. Make sure DIP switches 5 and 8 of S7 are ON to boot in the emulation mode.
    9. In the console window, you will find the PLL and DDR frequencies getting set by the GEL file.
    10. It is a good practice to reset the CPU by going to Run -> Reset -> CPU Reset
    11. Now go to Run -> Load -> Load Program
    12. Browse to c6sdk_02_00_00_00\demos\facedetect\bin\{COMPILATION_METHOD}\evmC6748\Release amd open facedetect_evmC6748.out
    13. Wait until the program is loaded. 
    14. Now run the program by going to Run -> Resume. If your hardware is set up correctly, you should be able to see a box around faces captured by the camera. For best results, stand a few feet away from the camera and make sure the camera is placed in such a way that your face and the camera are exactly at the same level. This is needed as it is a frontal face detection demo. Also, for the same reason, make sure your head is not tilted with respect to the camera.

    Modify your factdetect code for streaming from USB webcam and build your project ,

    If you can build successfully build and then load facedetect_evmC6748.out  into your board through emulator

  • hi titus.s

    i am using OMAPL138LCDK with texas instrument XDS100v2 Emulator on CCS5.5

    as per your suggestion i followed

    1. Ensure that the Hardware is setup as explained in Hardware Setup for Demos in User Guide.
    2. Open CCSv5.1 and launch the target configuration file for TMS320C6748 or OMAPL138
    3. Go to Tools -> GEL Files 
    4. Right click inside the GEL Files window and select Load GEL.
    5. Browse to the pdk_C6748 folder -> gel and select C6748.gel
    6. The loaded gel file will be in GEL Files window. 
    7. In the Debug window, Right click on "Spectrum Digital XDS510USB Emulator_0/C674X_0 [Non-Project Debug Session]" -> Connect Target (Make sure the EVMC6748/LCDK is ON before saying Connect Target)
    8. Make sure DIP switches 5 and 8 of S7 are ON to boot in the emulation mode.
    9. In the console window, you will find the PLL and DDR frequencies getting set by the GEL file.
    10. It is a good practice to reset the CPU by going to Run -> Reset -> CPU Reset
    11. Now go to Run -> Load -> Load Program
    12. Browse to c6sdk_02_00_00_00\demos\facedetect\bin\{COMPILATION_METHOD}\evmC6748\Release amd openfacedetect_evmC6748.out
    13. Wait until the program is loaded. 
    14. Now run the program by going to Run -> Resume. If your hardware is set up correctly, you should be able to see a box around faces captured by the camera. For best results, stand a few feet away from the camera and make sure the camera is placed in such a way that your face and the camera are exactly at the same level. This is needed as it is a frontal face detection demo. Also, for the same reason, make sure your head is not tilted with respect to the camera.

    following these steps after 13 step by loading the program the resume button on run  does not get enabled it remains to that only 

    in the 7th step after connecting tar get i got this on console

    C674X_0: Output: Target Connected.
    C674X_0: Output: ---------------------------------------------
    C674X_0: Output: Memory Map Cleared.
    C674X_0: Output: ---------------------------------------------
    C674X_0: Output: Memory Map Setup Complete.
    C674X_0: Output: ---------------------------------------------
    C674X_0: Output: KICK Unlocked.
    C674X_0: Output: ---------------------------------------------
    C674X_0: Output: PSC Enable Complete.
    C674X_0: Output: ---------------------------------------------
    C674X_0: Output: PLL0 init done for Core:300MHz, EMIFA:25MHz
    C674X_0: Output: mDDR initialization is in progress....
    C674X_0: Output: PLL1 init done for DDR:150MHz
    C674X_0: Output: Using mDDR settings
    C674X_0: Output: mDDR init for 150 MHz is done
    C674X_0: Output: ---------------------------------------------

    in the 5th step i use c6748.gel is it fine with L138LCDK kit?

    also in 12th step i have loaded the facedetect_LCDK.out

    it did not able executed the program i cant run the demo on ccs.

    plz help.

  • Hi,

    Can you please tell us what are the changes have you done for making the code to use USB webcam,

    mean while test and debug through emulator at your end ( step by step ) by loading your .out files.

  • hi Mr.Sivaraj

    how can i change the facedetect demo code for USB camera.  from where i can extract and understand the coding part the instructions that is used. where it is given how to use instructions for OMAPl138LCDK? . 

    Plz link some examples regarding instructions used for interfacing of different module with OMAPl138 LCDK

  • plz help i can't able to perform any task using USB webcam for facedetect demo?

    where i need to change the programming for facedetect demo using USB webcam