void image_projecting ()函数该如何进行优化呢?
时间:10-02
整理:3721RD
点击:
求助各位大侠下面这段程序中的void image_projecting ()函数该如何进行优化呢?进行线性汇编的话该如何进行代码修改呢?* FILENAME: app_process.c
* PLATFORM: VC6.0
*
* The c file is used to compute the projection iamge
*
*
\******************************************************************************/
/*--------------the head file declaration-------------------------------------*/
#include
#include
#include
#include "app_extern.h"
#include "app_main.h"
/*---------------------------------------------------------------------------------------*/
/*----------------------the function of computing the prejectiong image -----------------*
* *
* 此函数用于计算该图像的目标放投影图 *
* 即:计算图像中每一点成为目标的概率 *
* 反投影图中越亮的点表明该点越有可能成为目标 *
* 由两部分在组成:1.计算目标的归一化直方图 *
* 2.计算各个像素点成为目标的概率 *
* 注:本文在图像上建立的坐标系如下图所示 *
* *
* 0---------------> X(352) *
* | *
* | *
* | *
* | *
* V y (288) *
/-----------------------------------------------------------------------------------------*/
void image_projecting ()
{
object_modeling(Y_data);
compute_prob_project(Y_data,Y_shadow);
}
/*------------------the function of computing the probility of the pixel -----------------*
* *
* 此函数用来计算图像中各像素点成为目标的概率 *
* *
/-----------------------------------------------------------------------------------------*/
void compute_prob_project(unsigned char *p_data ,unsigned char*p_data_project)
{
int i ;
unsigned short *prob=Histogram_object;
unsigned char temp;
for(i=0;i<sum_pixel;i++)
{
temp=*(p_data++);
*p_data_project++=(unsigned char)(*(prob+temp));
}
}
/*----------------------the function of compute the histogram ---------------------------*
* *
* 此函数用来计算目标的归一化直方图 *
* *
/-----------------------------------------------------------------------------------------*/
void object_modeling(unsigned char *p_data)
{
unsigned short *prob=Histogram_object;
int i,j,t;
unsigned short x1=object_location_x1;
unsigned short x2=object_location_x2;
unsigned short y1=object_location_y1;
unsigned short y2=object_location_y2;
unsigned short scale_window;
scale_window=(x2-x1)*(y2-y1);
memset(prob,0,512);
for(j=y1;j<y2;j++)
{
for(i=x1;i<x2;i++)
{
*(prob+(*(p_data+j*width+i)))+=1;
}
}
for(i=0;i<256;i++)
{
*(prob+i)= *(prob+i)*255*3/scale_window;
}
printf("The object model is constructed\n");
}
/*-------------------the function of drawing a window around the object ------------------*
* *
* 此函数用来标注目标在图像中的位置 *
* *
/-----------------------------------------------------------------------------------------*/
void draw_window (unsigned char *src_data )
{
int i ;
unsigned short x1=object_location_x1;
unsigned short x2=object_location_x2;
unsigned short y1=object_location_y1;
unsigned short y2=object_location_y2;
unsigned short window_w=x2-x1;
unsigned short window_h=y2-y1;
unsigned char *src;
src=src_data+y1*width+x1;
/****************标注平行于x轴的框子*************************************/
for(i=0;i<window_w;i++)
{
*(src+i)=255;
*(src+width+i)=255;
*(src+i+(window_h-1)*width)=255;
*(src+i+window_h*width)=255;
}
/****************标注平行于y轴的框子*************************************/
for(i=0;i<window_h;i++)
{
*(src+i*width)=255;
*(src+i*width+1)=255;
*(src+i*width+window_w)=255;
*(src+i*width+window_w-1)=255;
}
}
/*----------------------the function of write the output information --------------------*
* *
* 此函数用来将所做的题目号和耗费时间加到图像数据中 *
* 注:* 请勿修改此项* *
/-----------------------------------------------------------------------------------------*/
void fun_out(unsigned char *buffer_in, float costtime)
{
int j ;
unsigned char num = 17;
double tt=costtime;
for (j = 0 ; j < 10; j ++)
{
buffer_in[j] = 0;
}
buffer_in[0] = num;
memcpy(&buffer_in[1],&tt,8);
}
/*********************************** end of the file **********************************************/
* PLATFORM: VC6.0
*
* The c file is used to compute the projection iamge
*
*
\******************************************************************************/
/*--------------the head file declaration-------------------------------------*/
#include
#include
#include
#include "app_extern.h"
#include "app_main.h"
/*---------------------------------------------------------------------------------------*/
/*----------------------the function of computing the prejectiong image -----------------*
* *
* 此函数用于计算该图像的目标放投影图 *
* 即:计算图像中每一点成为目标的概率 *
* 反投影图中越亮的点表明该点越有可能成为目标 *
* 由两部分在组成:1.计算目标的归一化直方图 *
* 2.计算各个像素点成为目标的概率 *
* 注:本文在图像上建立的坐标系如下图所示 *
* *
* 0---------------> X(352) *
* | *
* | *
* | *
* | *
* V y (288) *
/-----------------------------------------------------------------------------------------*/
void image_projecting ()
{
object_modeling(Y_data);
compute_prob_project(Y_data,Y_shadow);
}
/*------------------the function of computing the probility of the pixel -----------------*
* *
* 此函数用来计算图像中各像素点成为目标的概率 *
* *
/-----------------------------------------------------------------------------------------*/
void compute_prob_project(unsigned char *p_data ,unsigned char*p_data_project)
{
int i ;
unsigned short *prob=Histogram_object;
unsigned char temp;
for(i=0;i<sum_pixel;i++)
{
temp=*(p_data++);
*p_data_project++=(unsigned char)(*(prob+temp));
}
}
/*----------------------the function of compute the histogram ---------------------------*
* *
* 此函数用来计算目标的归一化直方图 *
* *
/-----------------------------------------------------------------------------------------*/
void object_modeling(unsigned char *p_data)
{
unsigned short *prob=Histogram_object;
int i,j,t;
unsigned short x1=object_location_x1;
unsigned short x2=object_location_x2;
unsigned short y1=object_location_y1;
unsigned short y2=object_location_y2;
unsigned short scale_window;
scale_window=(x2-x1)*(y2-y1);
memset(prob,0,512);
for(j=y1;j<y2;j++)
{
for(i=x1;i<x2;i++)
{
*(prob+(*(p_data+j*width+i)))+=1;
}
}
for(i=0;i<256;i++)
{
*(prob+i)= *(prob+i)*255*3/scale_window;
}
printf("The object model is constructed\n");
}
/*-------------------the function of drawing a window around the object ------------------*
* *
* 此函数用来标注目标在图像中的位置 *
* *
/-----------------------------------------------------------------------------------------*/
void draw_window (unsigned char *src_data )
{
int i ;
unsigned short x1=object_location_x1;
unsigned short x2=object_location_x2;
unsigned short y1=object_location_y1;
unsigned short y2=object_location_y2;
unsigned short window_w=x2-x1;
unsigned short window_h=y2-y1;
unsigned char *src;
src=src_data+y1*width+x1;
/****************标注平行于x轴的框子*************************************/
for(i=0;i<window_w;i++)
{
*(src+i)=255;
*(src+width+i)=255;
*(src+i+(window_h-1)*width)=255;
*(src+i+window_h*width)=255;
}
/****************标注平行于y轴的框子*************************************/
for(i=0;i<window_h;i++)
{
*(src+i*width)=255;
*(src+i*width+1)=255;
*(src+i*width+window_w)=255;
*(src+i*width+window_w-1)=255;
}
}
/*----------------------the function of write the output information --------------------*
* *
* 此函数用来将所做的题目号和耗费时间加到图像数据中 *
* 注:* 请勿修改此项* *
/-----------------------------------------------------------------------------------------*/
void fun_out(unsigned char *buffer_in, float costtime)
{
int j ;
unsigned char num = 17;
double tt=costtime;
for (j = 0 ; j < 10; j ++)
{
buffer_in[j] = 0;
}
buffer_in[0] = num;
memcpy(&buffer_in[1],&tt,8);
}
/*********************************** end of the file **********************************************/
要沉的节奏吗。请求知道的兄弟姐妹们指导一二啊
三条建议:(1)将指针类型,评估占用空间大小,定义为数组类型。 (2)去掉printf语句,使用串口或者iic,上传打印信息。 (3)然后可以评估你使用的dsp或者mcu的空间是否满足你的要求。 期待将你要移植的目标,回复。