void MainWindow::rawtojpg()
{
QFile raw("C:\\Users\\Administrator\\Desktop\\avi\\00000000_009.raw");
if (!raw.open(QIODevice::ReadWrite))
return;
char *pDate = new char[CMOS_INPUT_WIDTH*CMOS_INPUT_HEIGHT];
raw.read(pDate,CMOS_INPUT_WIDTH*CMOS_INPUT_HEIGHT);
quint32 *pRgb = new quint32[CMOS_INPUT_WIDTH * CMOS_INPUT_HEIGHT];
//convert gray image to rgb;
for (int h = 0; h < CMOS_INPUT_HEIGHT; h++){
for (int row = 0; row < CMOS_INPUT_WIDTH; row++) {
quint32 gray = (int)pDate[CMOS_INPUT_WIDTH * h + row];
quint32 argb32 = gray << 16 | gray << 8 | gray | 0xff000000;
pRgb[CMOS_INPUT_WIDTH * h + row] = argb32;
}
}
QImage grayImage((uchar *)pRgb,CMOS_INPUT_WIDTH,CMOS_INPUT_HEIGHT,QImage::Format_RGB32);
QImage newimage = grayImage.scaled (ui->image_label->width (),ui->image_label->height ());
ui->image_label->setPixmap(QPixmap::fromImage(newimage));
QImage image;
//image.load ("C:\\Users\\Administrator\\Desktop\\image\\7.jpg");
pupiltwoValued(&grayImage, &grayImage);
//grayImage.save("C:\\Users\\Administrator\\Desktop\\grayTest.jpg");
delete pDate;
delete pRgb;
}
第二种:
int MainWindow::raw2rgb(void)
{
char *rawFileName = "./6500_1920x1080.raw";
QString fileNames = QApplication::applicationDirPath ();
fileNames.append ("/resource/0.jpg");
FILE *fp = NULL;
int ret = 0, width = 1280, height = 1024;
/*为读取14bit raw数据分配空间*/
unsigned short *pRawData = (unsigned short *)calloc(width*height, sizeof(unsigned short));
if (NULL == pRawData)
{
qDebug()<<"Fail to calloc buf:";
return -1;
}
if (NULL == (fp=fopen(fileNames.toStdString ().c_str (), "rb")))
{
qDebug()<<"Fail to read";
return -2;
}
ret = fread(pRawData,sizeof(unsigned short)*width*height,1, fp);
if (ret != 1)
{
qDebug()<<"Fail to read raw data";
return -3;
}
IplImage *pBayerData = cvCreateImage(cvSize(width,height), 16, 1);
IplImage *pRgbDataInt16 = cvCreateImage(cvSize(width,height),16,3);
IplImage *pRgbDataInt8 = cvCreateImage(cvSize(width,height),8,3);
memcpy(pBayerData->imageData, (char *)pRawData, width*height*sizeof(unsigned short));
cvCvtColor(pBayerData, pRgbDataInt16, CV_BayerRG2BGR);
/*将16bit数据转换为8bit*/
cvConvertScale(pRgbDataInt16, pRgbDataInt8, 0.015625, 0);
cvNamedWindow("rgb", 1);
cvShowImage("rgb", pRgbDataInt8);
cvWaitKey(0);
free(pRawData);
fclose(fp);
cvDestroyWindow("rgb");
cvReleaseImage(&pBayerData);
cvReleaseImage(&pRgbDataInt8);
cvReleaseImage(&pRgbDataInt16);
return 0;
}