// resize.h
// 2020/03/04 by marsee
#ifndef __resize_gray_H__
#define __resize_gray_H__
#include "ap_axi_sdata.h"
#include "hls_video.h"
#define ORG_HEIGHT 600
#define ORG_WIDTH 800
typedef hls::stream<ap_axiu<32,1,1,1> > AXI_STREAM;
typedef hls::Mat<ORG_HEIGHT, ORG_WIDTH, HLS_8UC3> RGB_IMAGE;
typedef hls::Mat<ORG_HEIGHT, ORG_WIDTH, HLS_8UC1> GRAY_IMAGE;
#define RESIZE_HEIGHT 45
#define RESIZE_WIDTH 60
#endif
// resize.cpp
// 2020/03/04 by marsee
#include "resize.h"
int resize(AXI_STREAM& ins, AXI_STREAM& outs){
#pragma HLS INTERFACE axis register both port=outs
#pragma HLS INTERFACE axis register both port=ins
#pragma HLS DATAFLOW
#pragma HLS INTERFACE s_axilite port=return
RGB_IMAGE org_img(ORG_HEIGHT, ORG_WIDTH);
RGB_IMAGE resize_img(RESIZE_HEIGHT, RESIZE_WIDTH);
hls::AXIvideo2Mat(ins, org_img);
hls::Resize(org_img, resize_img);
hls::Mat2AXIvideo(resize_img, outs);
return(0);
}
// resize_tb.cpp
// 2020/03/04 by marsee
#include <iostream>
#include "hls_opencv.h"
#include "resize.h"
using namespace cv;
#define INPUT_IMAGE "straight0.bmp"
#define OUTPUT_IMAGE "test_straight0.bmp"
#define OUTPUT_IMAGE_CV "test_straight0_cv.bmp"
void resize(AXI_STREAM& ins, AXI_STREAM& outs);
void opencv_resize(Mat& src, Mat& dst);
int main (int argc, char** argv) {
// OpenCV で 画像を読み込む
Mat src = imread(INPUT_IMAGE);
AXI_STREAM src_axi, dst_axi;
// Mat フォーマットから AXI4 Stream へ変換
cvMat2AXIvideo(src, src_axi);
// resize() 関数をコール
resize(src_axi, dst_axi);
// AXI4 Stream から Mat フォーマットへ変換
// dst は宣言時にサイズとカラー・フォーマットを定義する必要がある
Mat dst(RESIZE_HEIGHT, RESIZE_WIDTH, CV_8UC3);
AXIvideo2cvMat(dst_axi, dst);
// Mat フォーマットからファイルに書き込み
imwrite(OUTPUT_IMAGE, dst);
// opencv_resize_gray() をコール
Mat dst_cv(RESIZE_HEIGHT, RESIZE_WIDTH, CV_8UC3);
opencv_resize(src, dst_cv);
imwrite(OUTPUT_IMAGE_CV, dst_cv);
// dst と dst_cv が同じ画像かどうか?比較する
for (int y=0; y<RESIZE_HEIGHT; y++){
Vec3b* dst_ptr = dst.ptr<Vec3b>(y);
Vec3b* dst_cv_ptr = dst_cv.ptr<Vec3b>(y);
for (int x=0; x<RESIZE_WIDTH; x++){
Vec3b dst_bgr = dst_ptr[x];
Vec3b dst_cv_bgr = dst_cv_ptr[x];
// bgr のどれかが間違っていたらエラー
if (std::pow(dst_bgr[0]-dst_cv_bgr[0], 2.0) > 1 || std::pow(dst_bgr[1]-dst_cv_bgr[1], 2.0) > 1
|| std::pow(dst_bgr[2]-dst_cv_bgr[2], 2.0) > 1){
printf("x = %d, y = %d, Error dst=%d,%d,%d dst_cv=%d,%d,%d\n", x, y,
dst_bgr[0], dst_bgr[1], dst_bgr[0], dst_cv_bgr[0], dst_cv_bgr[1], dst_cv_bgr[2]);
//return 1;
}
}
}
printf("Test with 0 errors.\n");
return 0;
}
void opencv_resize(Mat& src, Mat& dst){
Mat img0(RESIZE_HEIGHT, RESIZE_WIDTH, CV_8UC3);
resize(src, img0, img0.size(), 0, 0, INTER_LINEAR);
img0.copyTo(dst);
}
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | - | - | - | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | - | - | - | - | - | - |