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
Observer rishubnagpal
Observer
493 Views
Registered: ‎04-19-2018

HLS_RGB2GRAY produces a blue image

Hi, I'm creating a simple video filter which converts an incoming 24-bit axi stream RGB image to grayscale. 

 

here is the code I am working with:

 

core.h

 

#ifndef _CORE_H_
#define _CORE_H_

#include "hls_video.h"

// maximum image size
#define MAX_WIDTH  640
#define MAX_HEIGHT 480

// I/O Image Settings
#define INPUT_IMAGE           "input.bmp"
#define OUTPUT_IMAGE          "result.bmp"

// typedef video library core structures
typedef hls::stream<ap_axiu<24,1,1,1> >               AXI_STREAM;
typedef hls::Scalar<2, unsigned char>                 YUV_PIXEL;
typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC2>     YUV_IMAGE;
typedef hls::Scalar<3, unsigned char>                 RGB_PIXEL;
typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC3>     RGB_IMAGE;

// top level function for HW synthesis
void image_filter(AXI_STREAM& src_axi, AXI_STREAM& dst_axi);

#endif

core.cpp

 

#include "core.h"

void image_filter(AXI_STREAM& src_axi, AXI_STREAM& dst_axi)
{
	RGB_IMAGE img(MAX_HEIGHT, MAX_WIDTH);
	RGB_IMAGE img2(MAX_HEIGHT, MAX_WIDTH);

	hls::AXIvideo2Mat(src_axi, img);
	hls::CvtColor<HLS_RGB2GRAY>(img, img2);
	hls::Mat2AXIvideo(img2, dst_axi);
}

Testbench:

 

#include "hls_opencv.h"
#include "core.h"

using namespace cv;


int main (int argc, char** argv) {
//    const char * inputfile = argc >= 2 ? argv[1] : INPUT_IMAGE;
//    const char * goldenfile = argc >= 3 ? argv[2] : OUTPUT_IMAGE_GOLDEN;

    Mat img = imread(INPUT_IMAGE);
    if (!img.data) {
        printf("ERROR: could not open or find the input image!\n");
        return -1;
    }

    AXI_STREAM src, dst;
    Mat outputimg = Mat::zeros(480, 640, CV_8UC3);
    cvMat2AXIvideo(img, src);
    image_filter(src, dst);
    AXIvideo2cvMat(dst,outputimg);

    imwrite(OUTPUT_IMAGE, outputimg);



    return 0;
}

This is the input image I am using: Input

 

and result:

 

result

 

 

 

Any idea why this is happening?

 

0 Kudos
1 Reply
Scholar u4223374
Scholar
466 Views
Registered: ‎04-26-2015

Re: HLS_RGB2GRAY produces a blue image

Why are you providing an RGB image as the output from RGB2GRAY? The whole point of the function is to produce a grayscale image.

 

I would guess that it's simply filling only one channel of your image; the result is that only one colour (blue) is displayed.

0 Kudos