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: 
Observer mokhtarbouain
Observer
9,362 Views
Registered: ‎03-21-2013

Get the pointer to the image buffer in the TOP function (Opencv)

Hi all,

I am using the Zc702 board and I aim to implement my algorithm with Vivado HLS.

So, I tested the SW algorithm and it worked. 

Now, I am using vivado HLS to generate the VHDL code, but I found some troubles. 

In fact I want to get the pointer to the image buffer in the TOP function (image ->imageData), but the vivado HLS generated an error.

In the test Bench I did this :

 

main()
{
.....
.....
IplImage* my_image = cvCreateImage(cvSize(width, height), 32, 1); 
AXI_STREAM  my_image_axi;
function (my_mage_axi, ...........................;)
AXIvideo2IplImage ( my_image_axi, my_image );

}

 And in my TOP function i did this :

 

void function (AXI_STREAM& image_1, ...........................;)
{
...........
unsigned char*image_ptr =(unsigned char*)image_1->imageData; //get the pointer to the image buffer
...........
}

When I run the C Synthesis the following error appear to me : 

 

code/top.cpp:60:58: error: member reference type 'AXI_STREAM' (aka 'stream<ap_axiu<32, 1, 1, 1> >') is not a pointer unsigned char *image_ptr= (unsigned char*) image_1->imageData;

So, there is a method to get the pointer to the image buffer in the TOP code?

Any help please?

Mokhtar.

 

 

0 Kudos
9 Replies
Teacher muzaffer
Teacher
9,341 Views
Registered: ‎03-31-2012

Re: Get the pointer to the image buffer in the TOP function (Opencv)

you need to do something like this:

RGB_IMAGE img_0(rows, cols);
hls::AXIvideo2Mat(input, img_0);

where input is of type AXI_STREAM&

or you can continue your  way:

 

IplImage* my_image = cvCreateImage(cvSize(width, height), 32, 1); 
AXI_STREAM  my_image_axi;
AXIvideo2IplImage ( my_image_axi, my_image );

 my_image is of type IplImage * which you should be able to manipulate.

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
Observer mokhtarbouain
Observer
9,326 Views
Registered: ‎03-21-2013

Re: Get the pointer to the image buffer in the TOP function (Opencv)

HI, 

Sorry, I have just forgotten to write in the first post: IplImage2AXIvideo, In fact I have this main

 

main()
{
.....
.....
IplImage* my_image = cvCreateImage(cvSize(width, height), 32, 1); 
AXI_STREAM  my_image_axi;
IplImage2AXIvideo(my_image, my_image_axi) function (my_mage_axi, ...........................;) AXIvideo2IplImage ( my_image_axi, my_image );

 

Any help please?

0 Kudos
Moderator
Moderator
9,317 Views
Registered: ‎04-17-2011

Re: Get the pointer to the image buffer in the TOP function (Opencv)

Can you post your complete code here if its not confidential?
Regards,
Debraj
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
0 Kudos
Observer mokhtarbouain
Observer
9,310 Views
Registered: ‎03-21-2013

Re: Get the pointer to the image buffer in the TOP function (Opencv)

Hi,

Yes it is confidential, that is why I gave an example.

But my problem is that I define an image in the main fucntion (test Bench) but I can't access to its imageData in the TOP fucntion.

That is means Icreate the image int the TestBench :

 

IplImage* my_image = cvCreateImage(cvSize(width, height), 32, 1);

 This image has  the image buffer and I need to use it in the TOP function :

 

unsigned char*image_ptr =(unsigned char*)image_1->imageData; //get the pointer to the image buffer

 

BOUAIN

 

0 Kudos
Observer mokhtarbouain
Observer
9,236 Views
Registered: ‎03-21-2013

Re: Get the pointer to the image buffer in the TOP function (Opencv)

Any help please ?

0 Kudos
Participant aitmhof
Participant
9,200 Views
Registered: ‎04-25-2014

Re: Get the pointer to the image buffer in the TOP function (Opencv)

The message states the problem img_1 is not a pointer nor is it a C++ class overload "->". So you can't use  the operator "->" .

Instead you must use "."

 

Regards,

 

Markus

0 Kudos
Observer mokhtarbouain
Observer
9,172 Views
Registered: ‎03-21-2013

Re: Get the pointer to the image buffer in the TOP function (Opencv)

Hi,

In fact it's struct, so I have to use "->"

 

typedef struct _IplImage
{
    int  nSize;             /* sizeof(IplImage) */
    int  ID;                /* version (=0)*/
    int  nChannels;         /* Most of OpenCV functions support 1,2,3 or 4 channels */
    int  alphaChannel;      /* Ignored by OpenCV */
    int  depth;             /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
                               IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported.  */
    char colorModel[4];     /* Ignored by OpenCV */
    char channelSeq[4];     /* ditto */
    int  dataOrder;         /* 0 - interleaved color channels, 1 - separate color channels.
                               cvCreateImage can only create interleaved images */
    int  origin;            /* 0 - top-left origin,
                               1 - bottom-left origin (Windows bitmaps style).  */
    int  align;             /* Alignment of image rows (4 or 8).
                               OpenCV ignores it and uses widthStep instead.    */
    int  width;             /* Image width in pixels.                           */
    int  height;            /* Image height in pixels.                          */
    struct _IplROI *roi;    /* Image ROI. If NULL, the whole image is selected. */
    struct _IplImage *maskROI;      /* Must be NULL. */
    void  *imageId;                 /* "           " */
    struct _IplTileInfo *tileInfo;  /* "           " */
    int  imageSize;         /* Image data size in bytes
                               (==image->height*image->widthStep
                               in case of interleaved data)*/
    char *imageData;        /* Pointer to aligned image data.         */
    int  widthStep;         /* Size of aligned image row in bytes.    */
    int  BorderMode[4];     /* Ignored by OpenCV.                     */
    int  BorderConst[4];    /* Ditto.                                 */
    char *imageDataOrigin;  /* Pointer to very origin of image data
                               (not necessarily aligned) -
                               needed for correct deallocation */
}
IplImage;

 

 

0 Kudos
Xilinx Employee
Xilinx Employee
9,169 Views
Registered: ‎08-17-2011

Re: Get the pointer to the image buffer in the TOP function (Opencv)

Hello Bouain,

I think you should read and read again XAPP1167;
In reference to "XAPP1167 (v2.0) August 27, 2013" I think that what you are trying to do is is the "pure" opencv software opencv_image_filter described on page 7.
What you need to do is the "image_filter" from page 8. There, the emphasis is on working on streams - because the FPGA doesn't have the internal memory to store your input image so the way this works is that everything is streamed and works at the pixel level.

At most a few lines will be buffured in the algorithm targetted to HLS.

I hopes this makes some sense.
- Hervé

SIGNATURE:
* New Dedicated Vivado HLS forums* http://forums.xilinx.com/t5/High-Level-Synthesis-HLS/bd-p/hls
* Readme/Guidance* http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369

* Please mark the Answer as "Accept as solution" if information provided is helpful.
* Give Kudos to a post which you think is helpful and reply oriented.
Participant aitmhof
Participant
9,118 Views
Registered: ‎04-25-2014

Re: Get the pointer to the image buffer in the TOP function (Opencv)

You state that your function looks like:

 

void function (AXI_STREAM& image_1...
...image_1->imageData;

so image_1 is a reference (-> &image_1) to some AXI_STREAM object, right? (aka stream<ap_axiu<32, 1, 1, 1> >). I don't know/haven't used the stream classes yet. So I can't recommed how to use it or tell  what members are available in AXI_STREAM. But

 

The error states that image_1 is no pointer (and apparently stream<ap_axiu<32, 1, 1, 1> > has no operator ->).

Public members of a struct/class object or reference  are accessed using "." and not "->".

So "->" can bused when:

class/stuct AXI_STREAM

....

 

 whatevertype operator->(void)

 

or if image_1 would be defined as a pointer (AXI_STREAM *image_1)

 

And like @herver said, you work on pixel basis (either streamed or bus-like). Depending on the algorithm it might

use line/block-buffers. Only the bus option would allow you to really random access the memory, but due to missing buffers, if you don't implement them yourself, the algorithm will have a poor performance.

 

Best Regards,

 

Markus

 

 

0 Kudos