UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor jlhx
Visitor
2,078 Views
Registered: ‎05-20-2014

How to use OpenCV on a Kintex 7?

Jump to solution

I want to do image processing on a Kintex 7 and Vivado HLS supports a subset of OpenCV functions which I want to use.

 

My problem is that all explanations in the User Guide (UG902) and the detailed explanation in the OpenCV Application Note (XAPP1167) all refer to a situation where a Zynq is used and the conversion to the data format all HLS-OpenCV functions expect is done via the the AXI-Transfer from the ARM-core to the FPGA fabric.

 

Is it possible to convert a 2D-Image stored in a custom data format (like uint8/0 with 1 channel) in a dual-port RAM into the required data-format "hls::Mat"? It doesn't seem that way, but XAPP1167 states under "Limitations" that "A second limitation is that the hls::Mat<> datatype used to model images is internally defined as a stream of pixels, using the hls::stream<> datatype, rather than as an array of pixels in external memory. " which makes me hopeful that a conversion is possible. Converting back should would be required as well.

 

Is this possible?

 

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Participant valato
Participant
2,828 Views
Registered: ‎09-29-2017

Re: How to use OpenCV on a Kintex 7?

Jump to solution

You just have to create stream from data stored in RAM. Something like this:

 

typedef ap_axiu<8, 1, 1, 1> axi_video_packet;
typedef hls::stream<axi_video_packet> axi_video_stream; void read(unsigned char input[M][N], axi_video_stream & output) {   for (int y = 0; y < M; y++)   for (int x = 0; x < N; x++)   { #pragma HLS LOOP_FLATTEN off
#pragma HLS LOOP_TRIPCOUNT max=10
#pragma HLS PIPELINE II=1     axi_video_packet packet;     packet.data = input[y][x];     packet.user = (x == 0 && y == 0)?1:0;     packet.last = (x == N - 1)?1:0;     packet.keep = -1;     output << packet;   } }

 

And after that you can go with hls::AXIvideo2Mat. Oposite direction is quite similar and easier since you just read packets and you don't care about TUSER and TLAST signal if your input is previously synchronized to TUSER and has appropriate size.

----- Please mark the post as an answer "Accept as solution" in case it helped to solve your problem. Give kudos in case the post guided you to the solution.

View solution in original post

6 Replies
Scholar austin
Scholar
2,056 Views
Registered: ‎02-27-2008

Re: How to use OpenCV on a Kintex 7?

Jump to solution

https://www.xilinx.com/support/.../xilinx2017_1/ug1233-xilinx-opencv-user-guide.pdf

 

(just google xilinx ug1223)

 

Does not look like we support OpenCV on Kintex (pretty much requires the processors).

 

 

 

 

 

Austin Lesea
Principal Engineer
Xilinx San Jose
0 Kudos
Scholar u4223374
Scholar
2,045 Views
Registered: ‎04-26-2015

Re: How to use OpenCV on a Kintex 7?

Jump to solution

@jlhx Yes! HLS provides a function called hls::AXIvideo2Mat which converts a regular hls::stream to a hls::Mat type (and a corresponding hls::Mat2AXIvideo which does the reverse).

 

All you need to do is get your image into an appropriate format - an AXI stream of the right width, with a single TUSER bit set at the first pixel of the frame, and a TLAST bit set on the last pixel of every line. If the image is in off-chip RAM (as it usually is, because images tend to be much larger than can be easily stored in block RAM) then the Xilinx VDMA block will read data from RAM and convert it to the correct AXI Stream format.

 

With regards to @austin's post: that was meant to be UG1233, not UG1223. True OpenCV is not supported on the FPGA (unless you want to recompile it for MicroBlaze), but it sounds like what you need is just the hls::CV side of things (ie hardware-friendly functions that do not rely on CPU involvement). As above, this is definitely achievable.

Visitor jlhx
Visitor
2,035 Views
Registered: ‎05-20-2014

Re: How to use OpenCV on a Kintex 7?

Jump to solution

Thanks for your reply u4223374!

 

And you're correct, I only want access to the subset of OpenCV/"video function" functionality described in UG 902, Chapter 2, "HLS Video Library" section.

 

Regarding your data type conversion description, do you know of any official Xilinx guideline, tutorial, example or anything else?

0 Kudos
Scholar u4223374
Scholar
2,028 Views
Registered: ‎04-26-2015

Re: How to use OpenCV on a Kintex 7?

Jump to solution

@jlhx The best I'm aware of is XAPP1167. It's designed more for Zynq (again), but if you just cut out the CPU-specific bits the rest is very relevant.

0 Kudos
Highlighted
Participant valato
Participant
2,829 Views
Registered: ‎09-29-2017

Re: How to use OpenCV on a Kintex 7?

Jump to solution

You just have to create stream from data stored in RAM. Something like this:

 

typedef ap_axiu<8, 1, 1, 1> axi_video_packet;
typedef hls::stream<axi_video_packet> axi_video_stream; void read(unsigned char input[M][N], axi_video_stream & output) {   for (int y = 0; y < M; y++)   for (int x = 0; x < N; x++)   { #pragma HLS LOOP_FLATTEN off
#pragma HLS LOOP_TRIPCOUNT max=10
#pragma HLS PIPELINE II=1     axi_video_packet packet;     packet.data = input[y][x];     packet.user = (x == 0 && y == 0)?1:0;     packet.last = (x == N - 1)?1:0;     packet.keep = -1;     output << packet;   } }

 

And after that you can go with hls::AXIvideo2Mat. Oposite direction is quite similar and easier since you just read packets and you don't care about TUSER and TLAST signal if your input is previously synchronized to TUSER and has appropriate size.

----- Please mark the post as an answer "Accept as solution" in case it helped to solve your problem. Give kudos in case the post guided you to the solution.

View solution in original post

Visitor jlhx
Visitor
1,998 Views
Registered: ‎05-20-2014

Re: How to use OpenCV on a Kintex 7?

Jump to solution
Thanks for your reply valato! I'll try this.
0 Kudos