[USF-XSim 62] 'compile' step failed with error(s). Please check the Tcl console output or 'Z:/Sim/CAMDS_FASTXt2_VDMAt_161/V_ZYBO_CAMDS_151.sim/sim_1/behav/xvhdl.log' file for more information.
ERROR: [VRFC 10-149] 'resetbridge' is not compiled in library xil_defaultlib [Z:/Sim/CAMDS_FASTXt2_VDMAt_161/V_ZYBO_CAMDS_151.ip_user_files/bd/V_ZYBO_CAMDS/ipshared/digilentinc.com/rgb2dvi_v1_2/src/ClockGen.vhd:56]
ERROR: [VRFC 10-149] 'syncasync' is not compiled in library xil_defaultlib [Z:/Sim/CAMDS_FASTXt2_VDMAt_161/V_ZYBO_CAMDS_151.ip_user_files/bd/V_ZYBO_CAMDS/ipshared/digilentinc.com/rgb2dvi_v1_2/src/ClockGen.vhd:64]
ERROR: [VRFC 10-1504] unit behavioral ignored due to previous errors [Z:/Sim/CAMDS_FASTXt2_VDMAt_161/V_ZYBO_CAMDS_151.ip_user_files/bd/V_ZYBO_CAMDS/ipshared/digilentinc.com/rgb2dvi_v1_2/src/ClockGen.vhd:46]
// fastx_on_serial.c
// 2016/04/13 by marsee
//
// Refered to http://japan.xilinx.com/support/documentation/sw_manuals_j/xilinx2014_4/ug902-vivado-high-level-synthesis.pdf
//
// 2016/04/21 : threshold をシリアル経由で入力する
//
#include <stdio.h>
#include "ximage_filter.h"
#include "xparameters.h"
int main(){
XImage_filter Ximage_filter;
XImage_filter_Config *Ximage_filterPtr;
int threshold;
// Look Up the device configuration
Ximage_filterPtr = XImage_filter_LookupConfig(0);
if (!Ximage_filterPtr){
fprintf(stderr, "XImage_filter configuration failed.\n");
return(-1);
}
// Initialize the Device
int Xlap_status = XImage_filter_CfgInitialize(&Ximage_filter, Ximage_filterPtr);
if (Xlap_status != XST_SUCCESS){
fprintf(stderr, "Could not Initialize XImage_filter\n");
return(-1);
}
// image_filter rows, cols set
XImage_filter_Set_cols(&Ximage_filter, (u32)800);
XImage_filter_Set_rows(&Ximage_filter, (u32)600);
// first shreshold set
printf("\n\rfirst threshold = ");
scanf("%d", &threshold);
XImage_filter_Set_threshold(&Ximage_filter, (u32)threshold);
// axis_switch_1, 1to2 ,Select M01_AXIS
// Refer to http://marsee101.blog19.fc2.com/blog-entry-3177.html
Xil_Out32((XPAR_CAMERA_INTERFACE_AXIS_SWITCH_1_BASEADDR+0x40), 0x80000000); // disable
Xil_Out32((XPAR_CAMERA_INTERFACE_AXIS_SWITCH_1_BASEADDR+0x44), 0);
Xil_Out32((XPAR_CAMERA_INTERFACE_AXIS_SWITCH_1_BASEADDR), 0x2); // Commit registers
// fastx filter AXIS Start
XImage_filter_Start(&Ximage_filter);
XImage_filter_EnableAutoRestart(&Ximage_filter);
// axis_switch_0, 2to1, Select S01_AXIS
// Refer to http://marsee101.blog19.fc2.com/blog-entry-3177.html
Xil_Out32((XPAR_CAMERA_INTERFACE_AXIS_SWITCH_0_BASEADDR+0x40), 0x1);
Xil_Out32((XPAR_CAMERA_INTERFACE_AXIS_SWITCH_0_BASEADDR), 0x2); // Commit registers
// threshold set
while(1){
printf("\n\rthreshold = ");
scanf("%d", &threshold);
if (threshold == 999)
break;
XImage_filter_Set_threshold(&Ximage_filter, (u32)threshold);
}
return(0);
}
//------------------------Address Info-------------------
// 0x00 : Control signals
// bit 0 - ap_start (Read/Write/COH)
// bit 1 - ap_done (Read/COR)
// bit 2 - ap_idle (Read)
// bit 3 - ap_ready (Read)
// bit 7 - auto_restart (Read/Write)
// others - reserved
// 0x04 : Global Interrupt Enable Register
// bit 0 - Global Interrupt Enable (Read/Write)
// others - reserved
// 0x08 : IP Interrupt Enable Register (Read/Write)
// bit 0 - Channel 0 (ap_done)
// bit 1 - Channel 1 (ap_ready)
// others - reserved
// 0x0c : IP Interrupt Status Register (Read/TOW)
// bit 0 - Channel 0 (ap_done)
// bit 1 - Channel 1 (ap_ready)
// others - reserved
// 0x10 : Data signal of rows
// bit 31~0 - rows[31:0] (Read/Write)
// 0x14 : reserved
// 0x18 : Data signal of cols
// bit 31~0 - cols[31:0] (Read/Write)
// 0x1c : reserved
// 0x20 : Data signal of threshold
// bit 31~0 - threshold[31:0] (Read/Write)
// 0x24 : reserved
// (SC = Self Clear, COR = Clear on Read, TOW = Toggle on Write, COH = Clear on Handshake)
//------------------------Parameter----------------------
void image_filter(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int cols, int threshold)
// opencv_ex_ug.cpp
// 2016/04/02 by marsee
// 2016/04/09 : FAST Corners Detection
#include "opencv_ex_ug.h"
void image_filter(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int cols, int threshold) {
#pragma HLS INTERFACE ap_stable port=threshold
#pragma HLS INTERFACE s_axilite port=threshold
#pragma HLS DATAFLOW
#pragma HLS INTERFACE ap_stable port=cols
#pragma HLS INTERFACE ap_stable port=rows
#pragma HLS INTERFACE s_axilite port=return
#pragma HLS INTERFACE axis port=OUTPUT_STREAM
#pragma HLS INTERFACE axis port=INPUT_STREAM
#pragma HLS INTERFACE s_axilite port=cols
#pragma HLS INTERFACE s_axilite port=rows
RGB_IMAGE img_0(rows, cols);
RGB_IMAGE img_1(rows, cols);
RGB_IMAGE img_1_(rows, cols);
#pragma HLS STREAM variable=img_1_.data_stream depth=8192
// FASTX に最大 7 ラインのレイテンシ、Dilate に最大 3 ラインのレイテンシがあるそうだ
// 1ラインのピクセル数X10 ラインのFIFO バッファが必要 800x10 < 8192 (2の13乗)
// http://japan.xilinx.com/support/documentation/application_notes/xapp1167.pdf
// の 10 ページ参照
GRAY_IMAGE img_1g(rows, cols);
GRAY_IMAGE mask(rows, cols);
GRAY_IMAGE dmask(rows, cols);
GRAY_IMAGE img_2g(rows, cols);
RGB_IMAGE img_3(rows, cols);
RGB_PIXEL color(255, 0, 0);
hls::AXIvideo2Mat(INPUT_STREAM, img_0);
hls::Duplicate(img_0, img_1, img_1_);
hls::CvtColor<HLS_BGR2GRAY>(img_1, img_1g);
hls::FASTX(img_1g, mask, threshold, true);
hls::Dilate(mask, dmask);
hls::PaintMask(img_1_, dmask, img_3, color);
hls::Mat2AXIvideo(img_3, OUTPUT_STREAM);
}
// 2016/04/03 : GRAY_IMAGE を追加
#ifndef __opencv_ex_ug_H__
#define __opencv_ex_ug_H__
#include "ap_axi_sdata.h"
#include "hls_video.h"
#define MAX_HEIGHT 600
#define MAX_WIDTH 800
typedef hls::stream<ap_axiu<32,1,1,1> > AXI_STREAM;
typedef hls::Scalar<3, unsigned char> RGB_PIXEL;
typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC3> RGB_IMAGE;
typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC1> GRAY_IMAGE;
#endif
// opencv_ex_ug_tb.cpp
// 2016/04/02 by marsee
// OpenCV 2 の Mat を使用したバージョン
// 2016/04/09 : FAST Corners Detection
#include <iostream>
#include "hls_opencv.h"
#include "opencv_ex_ug.h"
using namespace cv;
#define INPUT_IMAGE "test.jpg"
#define OUTPUT_IMAGE "test_result.jpg"
#define OUTPUT_IMAGE_CV "test_result_cv.jpg"
#define THESHOLD_LEVEL 60
void image_filter(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int cols, int threshold);
void opencv_imaga_filter(Mat& src, Mat& dst, int threshold);
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);
// image_filter() 関数をコール
image_filter(src_axi, dst_axi, src.rows, src.cols, THESHOLD_LEVEL);
// AXI4 Stream から Mat フォーマットへ変換
// dst は宣言時にサイズとカラー・フォーマットを定義する必要がある
Mat dst(src.rows, src.cols, CV_8UC3);
AXIvideo2cvMat(dst_axi, dst);
// Mat フォーマットからファイルに書き込み
imwrite(OUTPUT_IMAGE, dst);
// opencv_image_filter() をコール
Mat dst_cv(src.rows, src.cols, CV_8UC3);
opencv_imaga_filter(src, dst_cv, THESHOLD_LEVEL);
imwrite(OUTPUT_IMAGE_CV, dst_cv);
// dst と dst_cv が同じ画像かどうか?比較する
for (int y=0; y<src.rows; y++){
Vec3b* dst_ptr = dst.ptr<Vec3b>(y);
Vec3b* dst_cv_ptr = dst_cv.ptr<Vec3b>(y);
for (int x=0; x<src.cols; x++){
Vec3b dst_bgr = dst_ptr[x];
Vec3b dst_cv_bgr = dst_cv_ptr[x];
// bgr のどれかが間違っていたらエラー
if (dst_bgr[0] != dst_cv_bgr[0] || dst_bgr[1] != dst_cv_bgr[1] || dst_bgr[2] != dst_cv_bgr[2]){
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_imaga_filter(Mat& src, Mat& dst, int threshold){
src.copyTo(dst); // 深いコピー
std::vector<Mat> layers;
std::vector<KeyPoint> keypoints;
split(src, layers);
FAST(layers[0], keypoints, threshold, true);
for (int i = 0; i < keypoints.size(); i++) {
rectangle(dst,
Point(keypoints[i].pt.x-1, keypoints[i].pt.y-1),
Point(keypoints[i].pt.x+1, keypoints[i].pt.y+1),
Scalar(255,0), CV_FILLED);
}
}
になった。#pragma HLS STREAM variable=img_1_.data_stream depth=8192
// opencv_ex_ug.cpp
// 2016/04/02 by marsee
// 2016/04/09 : FAST Corners Detection
#include "opencv_ex_ug.h"
void image_filter(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int
cols) {
#pragma HLS DATAFLOW
#pragma HLS INTERFACE ap_stable port=cols
#pragma HLS INTERFACE ap_stable port=rows
#pragma HLS INTERFACE s_axilite port=return
#pragma HLS INTERFACE axis port=OUTPUT_STREAM
#pragma HLS INTERFACE axis port=INPUT_STREAM
#pragma HLS INTERFACE s_axilite port=cols
#pragma HLS INTERFACE s_axilite port=rows
RGB_IMAGE img_0(rows, cols);
RGB_IMAGE img_1(rows, cols);
RGB_IMAGE img_1_(rows, cols);
#pragma HLS STREAM variable=img_1_.data_stream depth=8192
// FASTX に最大 7 ラインのレイテンシ、Dilate に最大 3 ラインのレイテンシがあるそうだ
// 1ラインのピクセル数X10 ラインのFIFO バッファが必要 800x10 < 8192 (2の13乗)
// http://japan.xilinx.com/support/documentation/application_notes/xapp1167.pdf
// の 10 ページ参照
GRAY_IMAGE img_1g(rows, cols);
GRAY_IMAGE mask(rows, cols);
GRAY_IMAGE dmask(rows, cols);
GRAY_IMAGE img_2g(rows, cols);
RGB_IMAGE img_3(rows, cols);
RGB_PIXEL color(255, 0, 0);
hls::AXIvideo2Mat(INPUT_STREAM, img_0);
hls::Duplicate(img_0, img_1, img_1_);
hls::CvtColor<HLS_BGR2GRAY>(img_1, img_1g);
hls::FASTX(img_1g, mask, 20, true);
hls::Dilate(mask, dmask);
hls::PaintMask(img_1_, dmask, img_3, color);
hls::Mat2AXIvideo(img_3, OUTPUT_STREAM);
}
// sobel_fil_on.c
// 2016/04/13 by marsee
//
// Refered to http://japan.xilinx.com/support/documentation/sw_manuals_j/xilinx2014_4/ug902-vivado-high-level-synthesis.pdf
//
#include <stdio.h>
#include "ximage_filter.h"
#include "xparameters.h"
int main(){
XImage_filter Ximage_filter;
XImage_filter_Config *Ximage_filterPtr;
// Look Up the device configuration
Ximage_filterPtr = XImage_filter_LookupConfig(0);
if (!Ximage_filterPtr){
fprintf(stderr, "XImage_filter configuration failed.\n");
return(-1);
}
// Initialize the Device
int Xlap_status = XImage_filter_CfgInitialize(&Ximage_filter, Ximage_filterPtr);
if (Xlap_status != XST_SUCCESS){
fprintf(stderr, "Could not Initialize XImage_filter\n");
return(-1);
}
// image_filter rows, cols set
XImage_filter_Set_rows(&Ximage_filter, (u32)600);
XImage_filter_Set_cols(&Ximage_filter, (u32)800);
// axis_switch_1, 1to2 ,Select M01_AXIS
// Refer to http://marsee101.blog19.fc2.com/blog-entry-3177.html
Xil_Out32((XPAR_CAMERA_INTERFACE_AXIS_SWITCH_1_BASEADDR+0x40), 0x80000000); // disable
Xil_Out32((XPAR_CAMERA_INTERFACE_AXIS_SWITCH_1_BASEADDR+0x44), 0);
Xil_Out32((XPAR_CAMERA_INTERFACE_AXIS_SWITCH_1_BASEADDR), 0x2); // Commit registers
// sobel filter AXIS Start
XImage_filter_Start(&Ximage_filter);
XImage_filter_EnableAutoRestart(&Ximage_filter);
// axis_switch_0, 2to1, Select S01_AXIS
// Refer to http://marsee101.blog19.fc2.com/blog-entry-3177.html
Xil_Out32((XPAR_CAMERA_INTERFACE_AXIS_SWITCH_0_BASEADDR+0x40), 0x1);
Xil_Out32((XPAR_CAMERA_INTERFACE_AXIS_SWITCH_0_BASEADDR), 0x2); // Commit registers
return(0);
}
// opencv_ex_ug_tb.cpp
// 2016/04/02 by marsee
// OpenCV 2 の Mat を使用したバージョン
// 2016/04/09 : FAST Corners Detection
#include <iostream>
#include "hls_opencv.h"
#include "opencv_ex_ug.h"
using namespace cv;
#define INPUT_IMAGE "test.jpg"
#define OUTPUT_IMAGE "test_result.jpg"
#define OUTPUT_IMAGE_CV "test_result_cv.jpg"
void image_filter(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int
cols);
void opencv_imaga_filter(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);
// image_filter() 関数をコール
image_filter(src_axi, dst_axi, src.rows, src.cols);
// AXI4 Stream から Mat フォーマットへ変換
// dst は宣言時にサイズとカラー・フォーマットを定義する必要がある
Mat dst(src.rows, src.cols, CV_8UC3);
AXIvideo2cvMat(dst_axi, dst);
// Mat フォーマットからファイルに書き込み
imwrite(OUTPUT_IMAGE, dst);
// opencv_image_filter() をコール
Mat dst_cv(src.rows, src.cols, CV_8UC3);
opencv_imaga_filter(src, dst_cv);
imwrite(OUTPUT_IMAGE_CV, dst_cv);
// dst と dst_cv が同じ画像かどうか?比較する
for (int y=0; y<src.rows; y++){
Vec3b* dst_ptr = dst.ptr<Vec3b>(y);
Vec3b* dst_cv_ptr = dst_cv.ptr<Vec3b>(y);
for (int x=0; x<src.cols; x++){
Vec3b dst_bgr = dst_ptr[x];
Vec3b dst_cv_bgr = dst_cv_ptr[x];
// bgr のどれかが間違っていたらエラー
if (dst_bgr[0] != dst_cv_bgr[0] || dst_bgr[1] != dst_cv_bgr[1] || dst_bgr[2] != dst_cv_bgr[2]){
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_imaga_filter(Mat& src, Mat& dst){
src.copyTo(dst); // 深いコピー
std::vector<Mat> layers;
std::vector<KeyPoint> keypoints;
split(src, layers);
FAST(layers[0], keypoints, 20, true);
for (int i = 0; i < keypoints.size(); i++) {
rectangle(dst,
Point(keypoints[i].pt.x-1, keypoints[i].pt.y-1),
Point(keypoints[i].pt.x+1, keypoints[i].pt.y+1),
Scalar(255,0), CV_FILLED);
}
}
// opencv_ex_ug.cpp
// 2016/04/02 by marsee
// 2016/04/09 : FAST Corners Detection
#include "opencv_ex_ug.h"
void image_filter(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int
cols) {
#pragma HLS DATAFLOW
#pragma HLS INTERFACE ap_stable port=cols
#pragma HLS INTERFACE ap_stable port=rows
#pragma HLS INTERFACE s_axilite port=return
#pragma HLS INTERFACE axis port=OUTPUT_STREAM
#pragma HLS INTERFACE axis port=INPUT_STREAM
#pragma HLS INTERFACE s_axilite port=cols
#pragma HLS INTERFACE s_axilite port=rows
RGB_IMAGE img_0(rows, cols);
RGB_IMAGE img_1(rows, cols);
RGB_IMAGE img_1_(rows, cols);
GRAY_IMAGE img_1g(rows, cols);
GRAY_IMAGE mask(rows, cols);
GRAY_IMAGE dmask(rows, cols);
GRAY_IMAGE img_2g(rows, cols);
RGB_IMAGE img_3(rows, cols);
RGB_PIXEL color(255, 0, 0);
hls::AXIvideo2Mat(INPUT_STREAM, img_0);
hls::Duplicate(img_0, img_1, img_1_);
hls::CvtColor<HLS_BGR2GRAY>(img_1, img_1g);
hls::FASTX(img_1g, mask, 20, true);
hls::Dilate(mask, dmask);
hls::PaintMask(img_1_, dmask, img_3, color);
hls::Mat2AXIvideo(img_3, OUTPUT_STREAM);
}
// 2016/04/03 : GRAY_IMAGE を追加
#ifndef __opencv_ex_ug_H__
#define __opencv_ex_ug_H__
#include "ap_axi_sdata.h"
#include "hls_video.h"
#define MAX_HEIGHT 600
#define MAX_WIDTH 800
typedef hls::stream<ap_axiu<32,1,1,1> > AXI_STREAM;
typedef hls::Scalar<3, unsigned char> RGB_PIXEL;
typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC3> RGB_IMAGE;
typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC1> GRAY_IMAGE;
#endif
hls::Sobel<1,1,3>(img_1g, img_2g);
Sobel(gray, img0g, IPL_DEPTH_16S, 1, 1, 3);
とした。X 軸方向の時は、hls::Sobel<0,1,3>(img_1g, img_2g);
だった。hls::Sobel<1,0,3>(img_1g, img_2g);
とした。X 軸方向の時はSobel(gray, img0g, IPL_DEPTH_16S, 0, 1, 3);
だった。、Sobel(gray, img0g, IPL_DEPTH_16S, 1, 0, 3);
// opencv_ex_ug_tb.cpp
// 2016/04/02 by marsee
// OpenCV 2 の Mat を使用したバージョン
// 2016/04/03 : グレー変換あり Sobel フィルタ
#include <iostream>
#include "hls_opencv.h"
#include "opencv_ex_ug.h"
using namespace cv;
#define INPUT_IMAGE "test.jpg"
#define OUTPUT_IMAGE "test_result.jpg"
#define OUTPUT_IMAGE_CV "test_result_cv.jpg"
void image_filter(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int
cols);
void opencv_imaga_filter(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);
// image_filter() 関数をコール
image_filter(src_axi, dst_axi, src.rows, src.cols);
// AXI4 Stream から Mat フォーマットへ変換
// dst は宣言時にサイズとカラー・フォーマットを定義する必要がある
Mat dst(src.rows, src.cols, CV_8UC3);
AXIvideo2cvMat(dst_axi, dst);
// Mat フォーマットからファイルに書き込み
imwrite(OUTPUT_IMAGE, dst);
// opencv_image_filter() をコール
Mat dst_cv(src.rows, src.cols, CV_8UC3);
opencv_imaga_filter(src, dst_cv);
imwrite(OUTPUT_IMAGE_CV, dst_cv);
// dst と dst_cv が同じ画像かどうか?比較する
for (int y=0; y<src.rows; y++){
Vec3b* dst_ptr = dst.ptr<Vec3b>(y);
Vec3b* dst_cv_ptr = dst_cv.ptr<Vec3b>(y);
for (int x=0; x<src.cols; x++){
Vec3b dst_bgr = dst_ptr[x];
Vec3b dst_cv_bgr = dst_cv_ptr[x];
// bgr のどれかが間違っていたらエラー
if (dst_bgr[0] != dst_cv_bgr[0] || dst_bgr[1] != dst_cv_bgr[1] || dst_bgr[2] != dst_cv_bgr[2]){
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_imaga_filter(Mat& src, Mat& dst){
Mat gray(src.rows, src.cols, CV_8UC1);
Mat img0g(src.rows, src.cols, CV_8UC1);
cvtColor(src, gray, CV_BGR2GRAY);
Sobel(gray, img0g, IPL_DEPTH_16S, 1, 0, 3);
cvtColor(img0g, dst, CV_GRAY2BGR);
}
// 2016/04/03 : GRAY_IMAGE を追加
#ifndef __opencv_ex_ug_H__
#define __opencv_ex_ug_H__
#include "ap_axi_sdata.h"
#include "hls_video.h"
#define MAX_HEIGHT 600
#define MAX_WIDTH 800
typedef hls::stream<ap_axiu<32,1,1,1> > AXI_STREAM;
typedef hls::Scalar<3, unsigned char> RGB_PIXEL;
typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC3> RGB_IMAGE;
typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC1> GRAY_IMAGE;
#endif
// opencv_ex_ug.cpp
// 2016/04/02 by marsee
// 2016/04/03 : グレー変換あり Sobel フィルタ
#include "opencv_ex_ug.h"
void image_filter(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int
cols) {
#pragma HLS DATAFLOW
#pragma HLS INTERFACE ap_stable port=cols
#pragma HLS INTERFACE ap_stable port=rows
#pragma HLS INTERFACE s_axilite port=return
#pragma HLS INTERFACE axis port=OUTPUT_STREAM
#pragma HLS INTERFACE axis port=INPUT_STREAM
#pragma HLS INTERFACE s_axilite port=cols
#pragma HLS INTERFACE s_axilite port=rows
RGB_IMAGE img_0(rows, cols);
GRAY_IMAGE img_1g(rows, cols);
GRAY_IMAGE img_2g(rows, cols);
RGB_IMAGE img_3(rows, cols);
hls::AXIvideo2Mat(INPUT_STREAM, img_0);
hls::CvtColor<HLS_BGR2GRAY>(img_0, img_1g);
hls::Sobel<1,0,3>(img_1g, img_2g);
hls::CvtColor<HLS_GRAY2BGR>(img_2g, img_3);
hls::Mat2AXIvideo(img_3, OUTPUT_STREAM);
}
// opencv_ex_ug_tb.cpp
// 2016/04/02 by marsee
// OpenCV 2 の Mat を使用したバージョン
#include <iostream>
#include "hls_opencv.h"
#include "opencv_ex_ug.h"
using namespace cv;
#define INPUT_IMAGE "test.bmp"
#define OUTPUT_IMAGE "test_result.bmp"
#define OUTPUT_IMAGE_CV "test_result_cv.bmp"
void image_filter(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int
cols);
void opencv_imaga_filter(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);
// image_filter() 関数をコール
image_filter(src_axi, dst_axi, src.rows, src.cols);
// AXI4 Stream から Mat フォーマットへ変換
// dst は宣言時にサイズとカラー・フォーマットを定義する必要がある
Mat dst(src.rows, src.cols, CV_8UC3);
AXIvideo2cvMat(dst_axi, dst);
// Mat フォーマットからファイルに書き込み
imwrite(OUTPUT_IMAGE, dst);
// opencv_image_filter() をコール
Mat dst_cv(src.rows, src.cols, CV_8UC3);
opencv_imaga_filter(src, dst_cv);
imwrite(OUTPUT_IMAGE_CV, dst_cv);
// dst と dst_cv が同じ画像かどうか?比較する
for (int y=0; y<src.rows; y++){
Vec3b* dst_ptr = dst.ptr<Vec3b>(y);
Vec3b* dst_cv_ptr = dst_cv.ptr<Vec3b>(y);
for (int x=0; x<src.cols; x++){
Vec3b dst_bgr = dst_ptr[x];
Vec3b dst_cv_bgr = dst_cv_ptr[x];
// bgr のどれかが間違っていたらエラー
if (dst_bgr[0] != dst_cv_bgr[0] || dst_bgr[1] != dst_cv_bgr[1] || dst_bgr[2] != dst_cv_bgr[2]){
printf("x = %d, y = %d, Error\n", x, y);
return 1;
}
}
}
printf("Test with 0 errors.\n");
return 0;
}
void opencv_imaga_filter(Mat& src, Mat& dst){
src.copyTo(dst); // 深いコピー
}
// opencv_ex_ug.c
// 2016/04/02 by marsee
// "Accelerating OpenCV Applications with Zynq-7000 All Programmable SoC using Vivado HLS Video Libraries"
// の 7 ページ下から、8 ページ上の image_filter() を参照しています。
// http://japan.xilinx.com/support/documentation/application_notes/xapp1167.pdf
#include "opencv_ex_ug.h"
void image_filter(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int
cols) {
#pragma HLS INTERFACE ap_stable port=cols
#pragma HLS INTERFACE ap_stable port=rows
#pragma HLS INTERFACE s_axilite port=return
#pragma HLS INTERFACE axis port=OUTPUT_STREAM
#pragma HLS INTERFACE axis port=INPUT_STREAM
#pragma HLS INTERFACE s_axilite port=cols
#pragma HLS INTERFACE s_axilite port=rows
RGB_IMAGE img_0(rows, cols);
hls::AXIvideo2Mat(INPUT_STREAM, img_0);
hls::Mat2AXIvideo(img_0, OUTPUT_STREAM);
}
#ifndef __opencv_ex_ug_H__
#define __opencv_ex_ug_H__
#include "ap_axi_sdata.h"
#include "hls_video.h"
#define MAX_HEIGHT 600
#define MAX_WIDTH 800
typedef hls::stream<ap_axiu<32,1,1,1> > AXI_STREAM;
typedef hls::Scalar<3, unsigned char> RGB_PIXEL;
typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC3> RGB_IMAGE;
#endif
#pragma HLS INTERFACE s_axilite port=return
#pragma HLS INTERFACE axis port=OUTPUT_STREAM
#pragma HLS INTERFACE axis port=INPUT_STREAM
#pragma HLS INTERFACE s_axilite port=cols
#pragma HLS INTERFACE s_axilite port=rows
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | - | - | - | 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 |