⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imglab.c

📁 基于dsp6416处理器的边缘检测算法
💻 C
字号:
/*=============================================================================
					Image Processing Examples on C64x

This example test Median Filtering.

Revision 1.0 2003/11/18
Copyright 2003 Wintech Digital. All Rights Reserved.
=============================================================================*/

#include <csl.h>
#include <csl_edma.h>
#include <csl_dat.h>
#include <std.h>
#include <sys.h>
#include <tsk.h>
#include <log.h>

#include "iekc64.h"
#include "agl.h"
#include "agl_string.h"
#include "agl_font.h"
#include "agl_font_lucida.h"
#include "img_median_3x3.h"
#include "img_ycbcr422p_rgb565.h"     //header file for C64x IMGLIB

#define DEMO_STANDARD   (PAL)
#define DEMO_RES      (RES_PAL_CIF)
#define DEMO_RES_VGA  (RES_VGA_PAL_352X576)
#define WIDTH    (352)
#define HEIGHT   (288)


#define FRAME_SIZE_IN_PIXELS  (WIDTH*HEIGHT)   //frame size for VIN


// DSP/BIOS object
extern Uint32 seg_sdrama;
extern far LOG_Obj myLOG; 

// Define image buffers
#define Frames_Count   4         // frames in the buffer
#define Frames_ToKeep  1         // frames to be kept in the buffer

#include "basic_op.h"


//	YUV422 pixels are 16 bits word, so Uint16
Uint16 CaptureBuffer[FRAME_SIZE_IN_PIXELS*Frames_Count]; // capture buffer
Uint8  InBufferY[FRAME_SIZE_IN_PIXELS];					 // seperated Y for VIN
Uint8  InBufferU[FRAME_SIZE_IN_PIXELS/2];				 // seperated U for VIN
Uint8  InBufferV[FRAME_SIZE_IN_PIXELS/2];				 // seperated V for VIN
Uint8  OutBufferY[FRAME_SIZE_IN_PIXELS];				 // seperated Y for VOUT
Uint8  OutBufferU[FRAME_SIZE_IN_PIXELS/2];				 // seperated U for VOUT
Uint8  OutBufferV[FRAME_SIZE_IN_PIXELS/2];				 // seperated V for VOUT

Uint16  worked_YUV[WIDTH*HEIGHT];

#ifdef VGA_OUT
Uint16  RGBBuffer[WIDTH*HEIGHT]; 						 //  out buffer for RGB
Uint16  OutputBuffer[FRAME_SIZE_IN_PIXELS*4];
static Int16 coeff[] = { 0x2543, 0x3313, -0x0C8A, -0x1A04, 0x408D };  // color-space-conversion matrix coefficients for YUV->RGB 
#else
Uint16 OutputBuffer[FRAME_SIZE_IN_PIXELS];               // out buffer for Comp
#endif


// Video moudle definition 
Handle			hVin;			// video input handle
Handle			hVout;			// video output handle


// Function definition
void tsk_main(void);      				//main task
void simpledelay(Uint32 delay_count);   //a simple delay funciton
void myImageProcess(void);				//image processing function



//
// Function implementation
//


//a simple delay funciton
void simpledelay(Uint32 delay_count)
{
	Uint32 i;
	for (i=0;i<delay_count; i++)
	{
		asm("	nop ");
	}

}



void main(void)
{
	IEKC64_STATUS	status;
	TSK_Attrs attrs;

	//
	// Remember you should call CSL_init() first when using CSL of DSP/BIOS
	//
 	CSL_init();

	//
	//	This is the first API call you need
	//  It is mandatory to initialize the board
	//
	status = IEKC64_init();
 	if (!IEKC64_SUCCESS(status))
 	{
 		printf( "IEKC64_Init() failed with 0x%08X\n", status );
 		abort();
 	}

   
	// Toggle the on board LEDs
	// First turn off all LEDs
   	LED_set( BRACKET_RED, ON );
 	LED_set( BRACKET_GREEN, ON );
 	LED_set( ONBOARD_GREEN, ON );
 	LED_set( ONBOARD_YELLOW, ON );
 	LED_set( ONBOARD_RED, ON );

	// Now toggle 
 	simpledelay(10000000);

	// Turn off again
   	LED_set( BRACKET_RED, OFF );
 	LED_set( BRACKET_GREEN, OFF );
 	LED_set( ONBOARD_GREEN, OFF );
 	LED_set( ONBOARD_YELLOW, OFF );
 	LED_set( ONBOARD_RED, OFF );

   
   
	// Notice for the users!!!
	// Put your application specific initialization function here!
	// 
	
	
	// Now create the main task
	attrs = TSK_ATTRS;
	attrs.priority = 4;
	attrs.stacksize = 9024;
	attrs.stackseg = seg_sdrama;
	TSK_create((Fxn)tsk_main, &attrs);
	// After the main() exit, DSP/BIOS will be entered.
}	


// This is the main task which will be entered after the DSP/BIOS was run
void tsk_main(void)
{
	IEKC64_STATUS	status;
	Uint32 i=0,j=0;
	Uint16* pRawData=NULL;			// pointer to raw image data
	Uint8*  temp_address=NULL;
	Uint16* temp_address1=NULL;

	Uint8*  pInBufferY=NULL;
	Uint8*  pInBufferU=NULL;
	Uint8*  pInBufferV=NULL;
	Uint8*  pOutBufferY=NULL;
	Uint8*  pOutBufferU=NULL;
	Uint8*  pOutBufferV=NULL;


	IEKC64_VIDEOOUT	videoOut = IEKC64_VIDEOOUT_DEFAULT;
	IEKC64_VIDEOIN	videoIn = IEKC64_VIDEOIN_DEFAULT;

#ifdef VGA_OUT
	memset(RGBBuffer,0x00,FRAME_SIZE_IN_PIXELS*sizeof(Uint16));
	memset(OutputBuffer,0x00,FRAME_SIZE_IN_PIXELS*4*sizeof(Uint16));
#else
	memset(OutputBuffer,0x8000,FRAME_SIZE_IN_PIXELS*sizeof(Uint16));
#endif


	//
	//	Now we prepare the VIN & VOUT moudle configurations 
	//	
	videoIn.Standard=DEMO_STANDARD;
	videoIn.Resolution=DEMO_RES;
	videoIn.FrameFormat=YUV422PIXEL;
	videoIn.VideoInSelect=COMPOSITE;
	videoIn.nTemporalDecimationFactor=1;
	videoIn.isOneShot=FALSE;
	videoIn.nFramesInBuffer=Frames_Count;
	videoIn.nFramesToKeep=Frames_ToKeep;
	videoIn.pCaptureBuffer=(Uint32*)CaptureBuffer;

#ifdef VGA_OUT
	videoOut.Standard=DEMO_STANDARD;
	videoOut.Resolution=DEMO_RES_VGA;
	videoOut.FrameFormat=RGB565PIXEL;
	videoOut.VideoOutSelect=VGA;	
#else
	videoOut.Standard=DEMO_STANDARD;
	videoOut.Resolution=DEMO_RES;
	videoOut.FrameFormat=YUV422PIXEL;
	videoOut.VideoOutSelect=COMPOSITE;	
#endif	
	//
	//	Let's open VIN & VOUT
	//	
	status = VIN_open(&videoIn,&hVin);
	if (!IEKC64_SUCCESS(status))
 	{
 		LOG_printf(&myLOG, "VIN_open() failed with 0x%08X\n", status );
 		abort();
 	}

	status = VOUT_open(&videoOut,&hVout);
	if (!IEKC64_SUCCESS(status))
 	{
 		LOG_printf(&myLOG, "VOUT_open() failed with 0x%08X\n", status );
 		abort();
 	}

#ifdef VGA_OUT
	// Open DAT copy module in 2D
	DAT_open(DAT_CHAANY,DAT_PRI_LOW,DAT_OPEN_2D);
#endif
	//
	//	Let's start video acquire & generation
	//	
	status = VOUT_start(hVout);
	if (!IEKC64_SUCCESS(status))
 	{
 		LOG_printf(&myLOG, "VOUT_start() failed with 0x%08X\n", status );
 		abort();
 	}

	status = VIN_start(hVin);
	if (!IEKC64_SUCCESS(status))
 	{
 		LOG_printf(&myLOG, "VIN_start() failed with 0x%08X\n", status );
 		abort();
 	}


	LOG_printf(&myLOG, "Image Processing Example Starts!\n\n");


	// The following is the framework for image processing


	//
	//	First try to get a frame at input
	//
	status = VIN_getFrame(hVin, (void**)&pRawData,IEKC64_VIDEO_WAIT_INFINITE);
	
	if (IEKC64_SUCCESS(status))
 	{
		// If we have the new frame, we can process it
	
			
    	// Porcessing begins!			 	
    	// First extract seperate Y/U/V from YUV 4:2:2 pixels 
		temp_address =(Uint8*)pRawData;   //point to Y0
			 	
		for (i=0;i<FRAME_SIZE_IN_PIXELS;i++)
			*(InBufferY+i) = *(temp_address+(i*2));
		
		temp_address++;						//point to U0
		for (i=0;i<FRAME_SIZE_IN_PIXELS/2;i++)
			*(InBufferU+i) = *(temp_address+(i*4));
		
		temp_address++;						//point to Y1
		temp_address++;						//point to V0
		for (i=0;i<FRAME_SIZE_IN_PIXELS/2;i++)
			*(InBufferV+i) = *(temp_address+(i*4));

	
		// Now you have seperated Y U V planes, you can process them as needed.
			
	    myImageProcess();	
	    	
	   	// Porcessing ends!
	    	

    	// Prepare the output buffer
		pInBufferY=&InBufferY[0];
		pInBufferU=&InBufferU[0];
		pInBufferV=&InBufferV[0];
		pOutBufferY=&OutBufferY[0];
		pOutBufferU=&OutBufferU[0];
		pOutBufferV=&OutBufferV[0];

		// To contrast the original image/processed image, we merge the two images
		// so that they could be simultaneously observed on the output screen.
		// The original image is on the left side while the processed image is on the right.
		temp_address1=OutputBuffer+(HEIGHT*WIDTH/4);
		
		// To output two images simultaneously, each image matrix is downsampled by 2.
		for (j=0;j<HEIGHT/2;j++)
		{
			for (i=0;i<WIDTH/4;i++)
			{
				*temp_address1 = (Uint16)(*pInBufferY)+(Uint16)((*pInBufferU)*256);
				*((Uint16*)(temp_address1+WIDTH/2)) = (Uint16)(*pOutBufferY)+(Uint16)((*pOutBufferU)*256);
				temp_address1++;
				pInBufferY+=2;	
				pOutBufferY+=2;
				pInBufferU+=2;
				pOutBufferU+=2;
				*temp_address1 = (Uint16)(*pInBufferY)+(Uint16)((*pInBufferV)*256);
				*((Uint16*)(temp_address1+WIDTH/2)) = (Uint16)(*pOutBufferY)+(Uint16)((*pOutBufferV)*256);
				temp_address1++;
				pInBufferY+=2;
				pOutBufferY+=2;
				pInBufferV+=2;
				pOutBufferV+=2;
			}			
			temp_address1+=(WIDTH/2);
			pInBufferY+=WIDTH;
			pOutBufferY+=WIDTH;
			pInBufferU+=(WIDTH/2);
			pOutBufferU+=(WIDTH/2);
			pInBufferV+=(WIDTH/2);
			pOutBufferV+=(WIDTH/2);
				
	    }	
    	// add string to indicate original and processed image
    	FONT_init();
    	STRING_putStringYUY2(OutputBuffer, WIDTH, "Original", WIDTH/4-32, HEIGHT/4-10, &font_lucida_8x8, 0x8080FF, 0x808000);
    	STRING_putStringYUY2(OutputBuffer, WIDTH, "Processed", WIDTH*3/4-50, HEIGHT/4-10, &font_lucida_8x8, 0x8080FF, 0x808000);
    		



#ifdef VGA_OUT
		temp_address =(Uint8*)OutputBuffer;   //point to Y0
		for (i=0;i<FRAME_SIZE_IN_PIXELS;i++)
			*(OutBufferY+i) = *(temp_address+(i*2));
		
		temp_address++;						//point to U0
		for (i=0;i<FRAME_SIZE_IN_PIXELS/2;i++)
			*(OutBufferU+i) = *(temp_address+(i*4));
		
		temp_address++;						//point to Y1
		temp_address++;						//point to V0
		for (i=0;i<FRAME_SIZE_IN_PIXELS/2;i++)
			*(OutBufferV+i) = *(temp_address+(i*4));

 		// Convert YUV 4:2:2 to RGB 16 bits format for VGA
 		// Refer to IMGLIB of TI for reference 
		IMG_ycbcr422p_rgb565( (short*) coeff, OutBufferY, OutBufferU, OutBufferV, RGBBuffer, FRAME_SIZE_IN_PIXELS);
    		
   		DAT_copy2d (DAT_1D2D, RGBBuffer, OutputBuffer, WIDTH*2 , HEIGHT , WIDTH*4);
   		DAT_copy2d (DAT_1D2D, RGBBuffer, &OutputBuffer[WIDTH], WIDTH*2  , HEIGHT , WIDTH*4);
#endif

    	// Now output the frame
   		VOUT_putFrame(hVout, OutputBuffer,IEKC64_VIDEO_NO_WAIT);
	    		
    	while(1)
    	{
    		asm("	nop	");
    	}
	
	}

}


#define U   148u
#define L   30u

// Notice for the users!!!
// Put your specific processing codes in the myImageProcess() function
// We will apply Laplacian mask to sharpen the original image
void myImageProcess()
{
	Uint32 i=0;
	float j=0;
	Uint8*  temp_address1=NULL;
	Uint8*  temp_address2=NULL;

DRAW_Point start,end;   
DRAW_Point point;       
Bool bStatus;	

struct YUV422_image img;

Uint8 * p_worked_YUV=(Uint8 *)&worked_YUV[0];

	temp_address1=&InBufferY[0];
	temp_address2=&OutBufferY[0];
        IMG_sobel(temp_address1,temp_address2,WIDTH,HEIGHT);
#if 0
	temp_address1=&InBufferU[0];
	temp_address2=&OutBufferU[0];
        IMG_sobel(temp_address1,temp_address2,WIDTH/2,HEIGHT);
        
	temp_address1=&InBufferV[0];
	temp_address2=&OutBufferV[0];
        IMG_sobel(temp_address1,temp_address2,WIDTH/2,HEIGHT);                
#else
	for (i=0; i<FRAME_SIZE_IN_PIXELS/2;i++)
	{
		OutBufferU[i]=0x80;
		OutBufferV[i]=0x80;
	}
#endif		

//	for (i=0; i<FRAME_SIZE_IN_PIXELS;i++)
//		OutBufferY[i]=0;					//make it black
//		OutBufferY[i]=255;					//make it white
	
//	for (i=0; i<FRAME_SIZE_IN_PIXELS/2;i++)
//	{
//		OutBufferU[i]=0x80;
//		OutBufferV[i]=0x80;
//	}

for(i=0;i<FRAME_SIZE_IN_PIXELS;i++)
	{
	}
	
/*	for (i=0; i<HEIGHT-3; i++)
	{
		temp_address1+=WIDTH;
		temp_address2+=WIDTH;
		IMG_median_3x3(temp_address1,WIDTH,temp_address2);
	}

	for (i=0; i<FRAME_SIZE_IN_PIXELS/2;i++)
	{
		InBufferU[i]=0x80;
		InBufferV[i]=0x80;
	}
*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -