1. 程式人生 > >Opencv讀取.dat格式CT資料

Opencv讀取.dat格式CT資料

近日研究CT三維重建功能,將.dat格式的讀取和顯示記錄下來,歡迎高手指點,共同進步。


#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <fstream>
using namespace std;
using namespace cv;


int main()
{
    ifstream file("*.dat", ios::in | ios::binary);

    int height = 512; //需要預先知道
    int width = 512;  //需要預先知道

    Mat img;
    img.create(height, width, CV_8UC1);
    file.read((char*)img.data, height*width);

    namedWindow("show", CV_WINDOW_NORMAL);
    resizeWindow("show", height, width);
    imshow("show", img);

    waitKey(0);


    return 0;
}