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: 
Highlighted
Visitor ritodoji
Visitor
602 Views
Registered: ‎03-20-2019

Cropping image function using HLS

Jump to solution

Hi everyone,

I'm new in HLS, I dont know how to implement a crop function using HLS because I usually use crop function from Cv2 or Pillow. And now, I want to know how to do it and any document I should read. I have already read Video Beginner Series 17 about Crop video but when I try change condition to crop then the log always loop this :
"WARNING: Hls::stream 'hls::stream<ap_axiu<24, 1, 1, 1> >.2' is read while empty, which may result in RTL simulation hanging."
Here my code changed :

#include "video_crop.h"

//Top Level Function
void video_crop(AXI_STREAM& s_axis_video,AXI_STREAM& m_axis_video, int hsize_in, int vsize_in)
{
#pragma HLS INTERFACE axis register both port=s_axis_video
#pragma HLS INTERFACE axis register both port=m_axis_video
	
	ap_axiu<24, 1, 1, 1> video;
	//AXI_STREAM video1;
	
	for(int i = 0; i < vsize_in ; i ++)
	  {
	         for(int j = 0; j < hsize_in ; j ++)
	         {
	        	 	 s_axis_video >> video;

	        	 	 if( i >vsize_in/2  )
	        	       	   {
	        	 		 	 
	        	 		 	 	 m_axis_video << video;
	        	 		 	 
	        	       	  }

	         }
	  }

}

// And testbench file :
#include "video_crop.h"
#include <hls_opencv.h>

int main (int argc, char** argv) {


	// Load data in OpenCV image format
	IplImage* src=cvLoadImage("13x.jpg");

	//Get input Image size
	CvSize size_in;
	size_in = cvGetSize(src);
	
	//Set output image size
	CvSize size_out;
	size_out.width = size_in.width;
	//size_out.height = size_in.height-size_in.height/2;
	size_out.height = size_in.height/2;
	//Create Destination image
	IplImage* dst = cvCreateImage(size_out, src->depth, src->nChannels);
	
	//Create the AXI4-Stream
	AXI_STREAM src_axi, dst_axi;

	// Convert OpenCV format to AXI4 Stream format
	IplImage2AXIvideo(src, src_axi);
	
	// Call the function to be synthesized
	video_crop(src_axi, dst_axi,size_in.width,size_in.height);
	
	// Convert the AXI4 Stream data to OpenCV format
	AXIvideo2IplImage(dst_axi, dst);
	
	// Standard OpenCV image functions
	cvSaveImage("/home/rito/Desktop/HLS_practice/XVES_0017/13x_2.jpg", dst);

	cvReleaseImage(&src);
	cvReleaseImage(&dst);

	return 0;
}

Thanks in advance for your help.

 

Best regards
Hung

0 Kudos
1 Solution

Accepted Solutions
Scholar u4223374
Scholar
564 Views
Registered: ‎04-26-2015

Re: Cropping image function using HLS

Jump to solution

I haven't fully verified this, but I think it'll be because you've dropped TUSER. Normally TUSER = 1 for the first pixel in a frame, and TLAST = 1 for the last pixel in each line. However, with the cropping you're doing, you've cut out the only place where TUSER = 1 (by only taking the second half of the image).

 

Also, your maths is off slightly. Take a very small image that's 8x6 pixels. You're only copying pixels when (i > vsize_in/2), which is to say i > 3. That means that in this example you would only copy lines 4 and 5, whereas I think you were expecting to use 3, 4, and 5.

2 Replies
Scholar u4223374
Scholar
565 Views
Registered: ‎04-26-2015

Re: Cropping image function using HLS

Jump to solution

I haven't fully verified this, but I think it'll be because you've dropped TUSER. Normally TUSER = 1 for the first pixel in a frame, and TLAST = 1 for the last pixel in each line. However, with the cropping you're doing, you've cut out the only place where TUSER = 1 (by only taking the second half of the image).

 

Also, your maths is off slightly. Take a very small image that's 8x6 pixels. You're only copying pixels when (i > vsize_in/2), which is to say i > 3. That means that in this example you would only copy lines 4 and 5, whereas I think you were expecting to use 3, 4, and 5.

Visitor ritodoji
Visitor
545 Views
Registered: ‎03-20-2019

Re: Cropping image function using HLS

Jump to solution
Thank you so much, from your help I see my problem here :
+ I didnt set video.last = 1 when it done
I tried it and my problem has gone !!!!! Yay
Once again, thanks you!!
0 Kudos