nv12_to_jpg

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <getopt.h>
#include <drm/drm_fourcc.h>
#include <basetypes.h>
#include <string>

#include "opencv/highgui.h"

using namespace std;

 

void NV12toBGR(unsigned char *bgrData, unsigned char *nv12Data, int width, int height)
{

}
int Convert(char *input, char *output)
{
    cv::Mat biggerImage(1080, 3520, CV_8UC3);

    int h,v;
    unsigned char * buff_in;
    unsigned char * buff_out;


    FILE* in = fopen( input, "rw+" );
    if ( in == NULL ) {
        printf("to_bj: open file %s failed\n", input);
        return -1;
    }

    buff_in = (unsigned char *)malloc(3320*1080*1.5);
    buff_out = (unsigned char *)malloc(3320*1080*3);

    fread(buff_in, 3320*1080*1.5 ,1 ,in);
    
    NV12toBGR(buff_out, buff_in,3320,1080);

    for(v=0;v<1080;v++){
        for(h=0;h<3520;h++){
            //biggerImage.at<Vec3b>(v, h)[0] =    buff_out[3320*v*3+3*h];
            //biggerImage.at<Vec3b>(v, h)[1] =    buff_out[3320*v*3+3*h+1];
            //biggerImage.at<Vec3b>(v, h)[2] =    buff_out[3320*v*3+3*h+2];
             biggerImage.at<cv::Vec3b>(v, h) = cv::Vec3f( buff_out[3320*v*3+3*h], buff_out[3320*v*3+3*h+1], buff_out[3320*v*3+3*h+2]);
        }
    }

    vector<int> compression_params;
    compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);  //选择jpeg
    compression_params.push_back(100);

    cv::imwrite(output,biggerImage,compression_params);
    fclose(in);
    free(buff_in);
    free(buff_out);
    return 0;
}

int main(int argc, char **argv)
{
    if(argc < 2)
        printf("to_bj: please input read file\n");

    char *input_name = argv[1];
    printf("to_bj: input file name:%s \n", input_name);
    
    char *output_name = argv[2];
    printf("to_bj: output file name:%s \n", output_name);

    int ret = Convert(input_name, output_name);
    if(ret < 0)
        printf("to_bj: convert failed!\n");


    return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值