项目中常用代码:保存图片、时间戳的获取与发送、log的打印

保存图片的代码:

    g2dHandle->perception_pic3->MapBo(); /*DDS 发送之前的必要操作*/
    char *pdata = (char*)g2dHandle->perception_pic3->handle.mapped_vaddrs[0];  /*perception_pic3 格式为rgb*/
#if 0
    static int flag = 0;               /*定义静态变量整型的 flag*/
    if(flag == 0 ){                    /* 该循环只进入一次*/
        cv::Mat Img(1000, 1000, CV_8UC4);/* cv::Mat 类型的 Img 大小1000*1000 格式CV_8UC4*/
        memcpy(Img.data,pdata,4000000);  /* void *memcpy(void *__restrict__ __dest, const void *__restrict__ __src, size_t __n)
        pdata是输入数据指针,大小是1000*1000*4*/
        imwrite("./image_t.png", Img); /*imwrite写函数,文件名,传入变量*/
        flag++;
    }
#endif  
    memcpy(pdata ,&VT_tv2,sizeof(struct timeval));
    VT_PSDSentImage(pdata);                /* DDS 发送接口 AVM -> PSD*/
    g2dHandle->perception_pic3->UnMapBo(); /*DDS 发送之前的必要操作*/
}
******************************************************************************/
void VT_SaveG2dBuffer(int g2d_index,int num)
{
    static VTint32 picCnt = 0,picIndex = 0;
    char filename[30];

    if(picCnt > num)
        return;
   
    if(picCnt++ )
    {
        sprintf(filename, "%sperception_pic%d_%d.rgb",CAMERA_DUMP_PATH,g2d_index,picIndex++);
        if(g2d_index == 0){
            g2dHandle->perception_pic0->dumpFile(filename);
        }else if(g2d_index == 1){
            g2dHandle->perception_pic1->dumpFile(filename);
        }else if(g2d_index == 2){
            g2dHandle->perception_pic2->dumpFile(filename);
        }else if(g2d_index == 3){
            g2dHandle->perception_pic3->dumpFile(filename);
        }
       
    }
}

时间戳的获取与发送

在当前的.cpp文件最开始的地方定义全局变量 VT_tv1
struct timeval VT_tv1;
在该文件的头文件中
extern struct timeval VT_tv1;
定义结构体 tv1; 获取当前的系统时间
/*******时间戳*****/
struct timeval tv1;
gettimeofday(&tv1, NULL);
VT_tv1.tv_sec = tv1.tv_sec;
VT_tv1.tv_usec = tv1.tv_usec;
/*****************/
在使用该时间戳的地方
memcpy((pdata + 1 ),&VT_tv1,sizeof(struct timeval));
给指针pdata第2位开始,拷贝进VT_tv1的地址,大小伟struct timeval

log的打印


static int cnt = 0;
if(cnt_ % 50 == 0)
{
    printf();
    cnt_ ++;
}
每隔50次打印一次
printf("---fun: %s---line: %d---------------------------------------------------\n", __func__, __LINE__);
打印当前的函数以及行数,用于Debug

打印mvp矩阵值
    // Print the values
    std::cout << "window: " << window << std::endl;
    std::cout << "param: " << param << std::endl;
    std::cout << "obj->gLookview: " << std::endl;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            std::cout << obj->gLookview[i][j] << " ";
        }
        std::cout << std::endl;
    }
    write(0, "111", 3);
    write(1, "111", 3);
    std::cout << "obj->gModelview: " << std::endl;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            std::cout << obj->gModelview[i][j] << " ";
        }
        std::cout << std::endl;
    }


    std::cout << "obj->gProjview: " << std::endl;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            std::cout << obj->gProjview[i][j] << " ";
        }
        std::cout << std::endl;
    }


    std::cout << "ScalingMatrix: " << std::endl;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            std::cout << ScalingMatrix[i][j] << " ";
        }
        std::cout << std::endl;
    }


    std::cout << "obj->mvp: " << std::endl;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
             std::cout << obj->mvp[i][j] << " ";
        }
        std::cout << std::endl;
    }

你可能感兴趣的:(开发语言)