2016-07-04 102 views
-1

我一直在嘗試使用vivado hls製作一箇中值濾波器。 有人建議我使用OpenCV imread函數,但是當我使用它時,即使我已經包含OpenCV庫,程序也不會識別它。 如果我不使用imread功能和使用墊子和cvLoadImage我得到一個錯誤說以下內容:使用Mat,並識別imread函數

/../HLSAXIStreamMedian_tb.cpp:109:15: error: missing template arguments before '.' token 

如果有人知道如何解決這個問題,或者給我一個替代我將不勝感激。 這是從我的測試臺代碼:

#include "HLSAXIStreamMedian.h" 

int main(void) { 

    spix imageIn[MAX_HEIGHT][MAX_WIDTH]; // May have to malloc these if they're large 
    spix imageOut[MAX_HEIGHT][MAX_WIDTH]; 
    spix imageGold[MAX_HEIGHT][MAX_WIDTH]; 

    static uint8_t frameIn[MAX_HEIGHT * MAX_WIDTH]; 

    FILE * imgFile = fopen("C:/img.bin","rb"); // "rb" is important - forces the image to be opened in binary mode. 

    fread(frameIn,1,MAX_HEIGHT*MAX_WIDTH,imgFile); 

    fclose(imgFile); 

    // Organise that data into the required image type. 

    spix dataIn[MAX_HEIGHT][MAX_WIDTH]; 

    for (int y = 0; y < MAX_HEIGHT; y++) { 
     for (int x = 0; x < MAX_WIDTH; x++) { 
      spix tmp; 
      tmp.data = frameIn[y*MAX_WIDTH + x]; 
      tmp.last = (x == (MAX_WIDTH-1)); 
      tmp.user = (x == 0) && (y == 0); 
      dataIn[y][x] = tmp; 
     } 
    } 

    // spix array is now initialised. 
// Mat gold(1212, 1216, CV_8UC3, Scalar(0,0, 100)); //create an image (3 channels, 8 bit image depth, 1212 high, 1216 wide, (0, 0, 100) assigned for Blue, Green and Red plane respectively.) 
// imageGold = gold; 
    IplImage* test = cvLoadImage("C:/MedianTrial/test_image.PNG"); 
    test = Mat.dataIn; 
    IplImage* gold = cvLoadImage("C:/MedianTrial/gold_output.PNG"); 
    gold = Mat.imageGold; 
    //Mat test; 
    //test = imread("C:/MedianTrial/test_image.PNG",in_pix); // Read a sample image. "imread" does not actually exist; read or generate an image using a method of your choice. 
    //Mat gold; 
    //gold = imread("C:/MedianTrial/gold_output.PNG",imageGold); // Read a known-good image (eg. generated using Matlab's median filter). 

    top_median(imageIn,imageOut,1080,1920); // Call the test function. 

    for (int i = 0; i < 1080; i++) { 
     for (int j = 0; j < 1920; j++) { 
      if (imageOut != imageGold) { 
       printf("Data mismatch");// at position (%d,%d): %d != %d\n",i,j,imageOut[i][j],imageGold[i][j]); 
       return -1; 
      } 
     } 
    } 
} 

這是頭文件:

#define KMED 3 // KMED can be 3, 5, 7 
#define KKMED 1 // KKMED == 1 for 3x3 window 
#define MIN(x,y) ((x)>(y) ? (y) : (x)) 
#define MAX(x,y) ((x)>(y) ? (x) : (y)) 
#include "opencv/cxcore.h" 
#include <opencv2/core/core.hpp> 
#include "opencv2/highgui/highgui.hpp" 
//opencv_core 
//opencv_imgcodecs 
//opencv_highgui 
#include <iostream> 
#include "hls_video.h" 
#include "hls_opencv.h" 
#include <ap_int.h> 
#include "ap_axi_sdata.h" 
#include <stdio.h> 
#include <string.h> 
#include <hls_stream.h> 
#include <stdlib.h> 
using namespace hls; 
//using namespace cv; 
//using namespace std; 
#include <ap_axi_sdata.h> 
typedef ap_axis<8,2,5,6> spix; 
#ifndef GRAY11 
typedef unsigned char pix_t; // 8-bit per pixel 
#else 
#include <ap_int.h> 
typedef ap_int<11> pix_t; // 11-bit per pixel 
#endif 
#define MAX_HEIGHT 1080 
#define MAX_WIDTH 1920 
void top_median(spix in_pix[MAX_HEIGHT][MAX_WIDTH], 
spix out_pix[MAX_HEIGHT][MAX_WIDTH], 
short int height, short int width); 
//spix in_pix[MAX_HEIGHT][MAX_WIDTH]; 
//spix out_pix[MAX_HEIGHT][MAX_WIDTH]; 
//spix out_pixtb[MAX_HEIGHT][MAX_WIDTH]; 
//short int height; 
//short int width; 
pix_t Median(pix_t window[KMED*KMED]); 
    enter code here 
    enter code here 
+0

我不知道你指的是圖書館,但使用'imread'在OpenCV中,你將需要'highgui'模塊,因此包括'highgui.h'或'highgui.hpp'。 –

+0

告訴我們您的預處理文件中哪一行是109。你沒有標記它,我們也不知道'#include'd標題爲了自己做數學要花多長時間。 –

+0

在頭文件中,我包含了這兩個庫(highgui.h和highgui.hpp) –

回答

0

我不能給你,因爲我沒有HLS庫,但可以指出您完整的解決方案正確的方向。

  1. 請勿使用using namespace ...

  2. 使用cvLoadImage()cv::imread()加載圖像。

  3. a。 (如果cvLoadImage)使用IplImage2hlsMat()IplImage*轉換爲hls::Mat。 b。 (如果imread)使用cvMat2hlsMat()cv::Mat轉換爲hls::Mat
    重要的是將hls::Mat轉換爲cv::Mat

  4. 創建hls::Window並使用您的過濾器對其進行初始化。
    [1,1,1]
    [1,1,1]
    [1,1,1]

  5. 使用hls::Filter2Dhls::Mathls::Window應用中值濾波。

參考文獻:

Article how to create filter in OpenCV
HLS doc

+0

非常感謝您提供的信息。我試圖使用cvMat2hlsMat(),但我得到的只是作爲imread()時,它會強調用紅色寫着「功能無法解析」好像我不包括簡歷庫,很奇怪,因爲我有它包括在內。有沒有特定的圖書館,可能我沒有收錄,或者是不同的問題?有任何想法嗎? –

+0

「cvLoadImage」呢?當你使用'imread'時你能複製整個錯誤信息嗎?你是否刪除了'using namespace'並且在'cv ::'中使用了'imread'? – Logman

+0

我寫過這樣的: –