我一直在尝试使用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 != %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 :(得分:0)
我不能给你完整的解决方案,因为我没有hls库,但可以指出你正确的方向。
请勿使用using namespace ...
。
使用cvLoadImage()
或cv::imread()
一个。 (如果cvLoadImage
)使用IplImage*
将hls::Mat
转换为IplImage2hlsMat()
。
b。 (如果imread
)使用cv::Mat
将hls::Mat
转换为cvMat2hlsMat()
。
转换为hls::Mat
而不是cv::Mat
。
创建hls::Window
并使用您的过滤器初始化它。
[1,1,1]
[1,1,1]
[1,1,1]
hls::Filter2D
和hls::Mat
一起使用hls::Window
来应用中位数过滤器。参考文献: