概述
#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>
using namespace std;
#include "opencv/highgui.h"
#ifndef PIXELVAL
#define PIXELVAL(x) (x < 0 ? 0 : (x > 255 ? 255 : x))
#endif
void met_image_CvtNV12toBGR(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 failedn", input);
return -1;
}
buff_in = (unsigned char *)malloc(3520*1080*1.5);
buff_out = (unsigned char *)malloc(3520*1080*3);
fread(buff_in, 3520*1080*1.5 ,1 ,in);
met_image_CvtNV12toBGR(buff_out, buff_in,3520,1080);
for(v=0;v<1080;v++){
for(h=0;h<3520;h++){
//biggerImage.at<Vec3b>(v, h)[0] = buff_out[3520*v*3+3*h];
//biggerImage.at<Vec3b>(v, h)[1] = buff_out[3520*v*3+3*h+1];
//biggerImage.at<Vec3b>(v, h)[2] = buff_out[3520*v*3+3*h+2];
biggerImage.at<cv::Vec3b>(v, h) = cv::Vec3f( buff_out[3520*v*3+3*h], buff_out[3520*v*3+3*h+1], buff_out[3520*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 filen");
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;
}
最后
以上就是高兴康乃馨为你收集整理的nv12_to_jpg的全部内容,希望文章能够帮你解决nv12_to_jpg所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复