cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
311 Views
Registered: ‎10-02-2020

init mat type

Hi

I have cpp source code that need to tranlslate to hls.

One sentence is the following.

Mat img_128(img_rows, img_cols, CV_32F, 128);

Do you have any idea how to init this Mat type? Put the xf::mat in the stream port?

0 Kudos
3 Replies
Highlighted
Moderator
Moderator
184 Views
Registered: ‎10-04-2011

Hello @jiajiahao069 ,

I think the best information to be found for the MAT class is located here:
https://xilinx.github.io/Vitis_Libraries/vision/2020.1/api-reference.html#xf-cv-mat-image-container-class

There are different class constructors to use and those are described there, with the one most likely to be of interest to you is:

  Mat(int _rows, int _cols, void* _data);

This would be initialized similar to that of the OpenCV matrix class where you declare a data array containing the initial values such as:

float data[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
cv::Mat opencv_matrix = cv::Mat(1, 10, CV_32F, data);

In HLS, arrays containing initial values will be initialized by incrementing through all of the array indices and writing the value, which for a large array, can be a significant source of latency, so caution is required to ensure this is absolutely necessary such as fixed values - a ROM. 

OK, I hope this helps,
Scott

0 Kudos
Highlighted
Visitor
Visitor
156 Views
Registered: ‎10-02-2020

Hi @scampbell 

Thanks for replying.

I did some tests about intinal the mat. But have some issues.

I want to initial the xf::cv::Mat<XF_8UC1,1080,1920,NPC> img_128 array. And I want to make the img_128_hls like a stream through in a processing ip.

I did it like the following code.

xf::cv::Mat<XF_8UC1,1080,1920,NPC> img_128_hls

for (int i = 0; i < 1080; i++)//上下
{
for (int j = 0; j < 1920; j++)
{
img_128_hls.data[i*img_cols+j] = 100;
}
}

and I initial a mat array in C-modle.

cv::Mat img_128;
img_128.create(cv::Size(1920,1080),CV_8UC1);

for (int i = 0; i < img_rows; i++)//上下左右
{
for (int j = 0; j < img_cols; j++)
{
//img_128.at<uchar>(i, j) = 5;
img_128.at<uchar>(i,j) = 100;

}
}

But I use

xf::cv::absDiff(img_128,img_128_hls, diff);

xf::cv::analyzeDiff(diff, 5, err_per);

get the final results

Minimum error in intensity = 100.000000
Maximum error in intensity = 100.000000
Percentage of pixels above error threshold = 100.000000

Could you tell me the reason why all pixels are wrong?

 

 

 

 

0 Kudos
Highlighted
Newbie
Newbie
114 Views
Registered: ‎11-08-2020


@scampbell wrote:

Hello @jiajiahao069 ,

I think the best information to be found for the MAT class is located here:
https://xilinx.github.io/Vitis_Libraries/vision/2020.1/api-reference.html#xf-cv-mat-image-container-class

There are different class constructors to use and those are described there, with the one most likely to be of interest to you is:

  Mat(int _rows, int _cols, void* _data);

This would be initialized similar to that of the OpenCV matrix class where you declare a data array containing the initial values such as:

float data[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
cv::Mat opencv_matrix = cv::Mat(1, 10, CV_32F, data);

In HLS, arrays containing initial values will be initialized by incrementing through all of the array indices and writing the value, which for a large array, can be a significant source of latency, so caution is required to ensure this is absolutely necessary such as fixed values - a ROM. 

OK, I hope this helps,
Scott


Thnks mate. will try roadrunner email this one

0 Kudos