1. 程式人生 > >OPencv直接開啟raw圖片檔案並檢視畫素

OPencv直接開啟raw圖片檔案並檢視畫素

opencv並不能直接開啟raw影象檔案,所以這裡我們要進行影象資料的拷貝;這裡是基於QT的

直接上程式碼:

static quint8 v4l2ConstantFrame[INPUT_VIDEO_W*INPUT_VIDEO_H*1];
static quint8 v4l2ConstantFrame1[INPUT_VIDEO_W*INPUT_VIDEO_H*1];

bool MainWindow::lockRawLmagePixel()
{
    memset(v4l2ConstantFrame,0,sizeof(v4l2ConstantFrame));
    //if path is empty. set it
    fileName.clear ();
    QString fileDir = QApplication::applicationDirPath ();
    fileName = QFileDialog::getOpenFileName(NULL,"open image",fileDir,"*.raw");

    qDebug() << imagePath;
    if (fileName.isEmpty())
        qDebug() << "imagePath = " << fileName;
    QFile raw(fileName);
    if  (!raw.open(QIODevice::ReadWrite)) {
        qDebug() << "file open error";
    }
    qDebug() << "file open success";
    raw.read((char*)v4l2ConstantFrame,1024*1280);
    memcpy(v4l2ConstantFrame1,v4l2ConstantFrame,1024*1280);
    cv::Mat mat_B(INPUT_VIDEO_H,INPUT_VIDEO_W,CV_8UC1);
    memcpy(mat_B.data, v4l2ConstantFrame, 1024*1280);
    if(!mat_B.empty ()){
        namedWindow("result+B", WINDOW_NORMAL);
        imshow("result+B", mat_B);
    }else
    {
        qDebug()<<"error:";
    }
    return 0;
}