raw格式(裸資料)格式檔案讀寫
阿新 • • 發佈:2018-12-31
raw格式檔案為裸資料,包含了相機原影象檔案在影象感測器產生後計入相機影象處理器之前的一切影象資訊。
從硬碟中讀取raw格式檔案存入opencv的影象容器中
將處理後的16點陣圖像資料儲存文raw格式檔案CString strPath= dlg.GetPathName(); CFile file; file.Open(strPath,CFile::modeRead|CFile::typeBinary); file.SeekToBegin(); BYTE * pfilebuf=new BYTE[m_width*m_hight*2] ;//相機採圖解析度 if (m_width*m_hight*2!= file.Read(pfilebuf,m_width*m_hight*2) ) { //提示檔案讀取錯誤 file.Close(); return; } file.Close(); CvMat* mat_a = cvCreateMat(1, m_width*m_hight, CV_16U); int i=0; do { unsigned short int a=0xffff; BYTE b = pfilebuf[i*2]; BYTE c = pfilebuf[i*2+1]; a= (c<<8)|b; CV_MAT_ELEM(*mat_a,unsigned short int, 0, i) =a; i++; }while(i<m_width*m_hight); delete[] pfilebuf; cvReshape(mat_a, mat_a, 0,m_hight); IplImage* img_a = cvCreateImage(cvSize(m_width,m_hight), IPL_DEPTH_16U, 1); cvCvtColor(mat_a, img_a, CV_BayerBG2GRAY); /*cvNamedWindow("raw"); cvShowImage("raw",img_a);*/ image=img_a; //cvReleaseImage(&img_a); cvReleaseMat(&mat_a); }
errno_t err1; FILE *pfile; err1=fopen_s(&pfile,"D:\\ceshiraw.raw","wb"); unsigned short int* pBes=NULL ;//指向型別的指標 pBes = new unsigned short int[img16.rows*img16.cols]; //處理影象的指標 memcpy(pBes,img16.data,img16.rows*img16.cols*2); if (pfile) { fwrite(pBes, sizeof(unsigned short)*img16.rows*img16.cols, 1, pfile); } fclose(pfile); delete [] pBes; pBes=NULL;