使用Mat,并识别imread功能



我一直在尝试使用vivado hls制作中值过滤器。有人建议我使用OpenCV imread函数,但是当我使用它时,即使我包含了OpenCV库,程序也无法识别它。如果我不使用imread函数并使用Mat和cvLoadImage,我会得到以下错误:

/../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 != %dn",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

我不能给你完整的解决方案,因为我没有hls库,但可以为你指出正确的方向。

  1. 不要使用using namespace ...

  2. 使用cvLoadImage()cv::imread()加载图像

  3. 。(如果cvLoadImage)使用IplImage2hlsMat()IplImage*转换为hls::Mat
    b. (if 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应用中值过滤器。

:

文章如何在OpenCV中创建过滤器
HLS医生

相关内容

  • 没有找到相关文章

最新更新