Wrong color using USB to PC transmitted by DevKit

Hi,

I use Kneron DevKit with GC2145 camera.

I try to build my own model and predict, it all works fine.

However, the image color shown on LCD is White->White, Red->Dark Red

the image color shown on PC(transmitted by USB) is White->Yellow, Red->Red

How can I get the right color display?

In my case, color is the main issue when predicting.

By the way, my USB transmit is written in this function:

static void kapp_yolo_draw_result(int buf_idx, struct dennis_result_s_l* dennis_result_p)

{

...

usb_com_write((uint8_t*)img_run[buf_idx].img_cfg.image_mem_addr, IMG_SIZE);

// last line

}


It sends image to PC correctly, but with a little color change.

PLZ help me solve this. Thank you!!

Comments

  • Hi Dennis,

    Is the SDK version you're using KL520 SDK v1.7.0?

    Also, are you using OpenCV on your PC? If so, OpenCV's default color format is BGR, and the color format KL520 SDK uses is RGB565, so you might want to convert your image to BGR before displaying.

  • Hi Maria,

    Yes, my SDK version is v1.7.0

    I do transfer the image as the code below:


    def RGB565toBGR(array):

      for i in range(480):

        for j in range(640):

          byte1 = (np.uint8)(array[i*640*2+j*2])

          byte2 = (np.uint8)(array[i*640*2+j*2+1])

          R = (np.uint8)(byte2&0xF8)

           

          G = ((np.uint8)(byte2&0x07)<<5)|(np.uint8)((byte1&0xE0)>>3)

           

          B = (np.uint8)((byte1&0x1F)<<3)

           

          R = R|((np.uint8)(B&0x38)>>3)

          G = G|((np.uint8)(G&0x0C)>>2)

          B = B|((np.uint8)(R&0x38)>>3)

           

          BGR_array[i,j,0] = B

          BGR_array[i,j,1] = G

          BGR_array[i,j,2] = R

      return BGR_array



    The image shows in PC actually looks like the "things" I capture, but the white part is a little yellow, not like LCD display is truely white.

    The red part in PC is correct, but LCD display is a little dark.

    I want to use the right color to train our model, so I should make sure these images are correct.

    Thank you


  • The image in PC looks like this

    To make sure the training effect from raw data, I turn off the AWB, AEC, gamma effects in camera driver. Is this the reason?

  • Hi Dennis,

    Thank you for providing your code. Since my code is in C, it's taking some time for me to reproduce the issue.

    I'm not sure if the AWB, AEC, and gamma effects would matter. Have you tried turning them on to see what the image looks like?

    We've edited the firmware function kapp_yolo_draw_result(...) and main.c inside tiny_yolo_v3_host_usbout/host_usb_receiver so that it outputs an image as a .bin file.

    The firmware included these new lines in yellow highlight:

    This is what we did with the main.c code. It should be possible to do something similar in Python as well.

    Could you try implementing that in your code and export the image to a .bin file and check if the colors look okay by using https://rawpixels.net/? The width x height is 640 x 480 respectively, and the predefined format should be RGB565.

    Thank you for your patience, I hope this helps.

  • Hi Dennis,

    If you were using usb.back.libusb1.get_backend(...) and usb.core.find(...) to connect to the KL520 USB, how do you get the image data transmitted from your USB? I'm getting the data by using:

    msg_in = usb.util.find_descriptor(interface, custom_match=lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_IN)

    Then, set usb_data as img, and set the RGB channels as the below

    The output image should look normal without any color changes:


  • Hi Dennis,

    I think I see your point now. The image on the PC and the display on the DevKit looks like they have different colors. When I tried it, the white parts also looked a little yellow, and the red parts' saturations looked a little different too.

    If you'd like to train your model, no worries about it; these two images are made of the same data. It's just that the displays are different (LCD and PC) so they look like they have different colors. The image displayed on your PC should be correct if it was transmitted correctly using USB.

  • Hi Maria:

    Thank you for the reply!!

    I used the code as follow to read USB:


    dev = usb.core.find(idVendor=0x3231, idProduct=0x0100)

    dev.set_configuration()

    data = dev.read(0x81, IMG_SIZE)

    img = RGB565toBGR(np.array(data))


    I saw you successfully transfer the image to PC, and the image truly looks different from LCD

    Your LCD seems a little bluer than mine.

    And your PC image seems a little lighter than mine.

    I turned on the AEC effects, the coffee beans in PC looks like:

    When I turned off the AEC effects, the coffee beans in PC looks like:

    My image actually becomes yellower...

    However, AEC is only about exposure... I dont understand the reason

    It looks like AWB issue... I'll try to figure out tomorrow

    light control is also important in our training, so I actually dont want to change exposure time(AEC).

    Thank you for reply again!!

  • Hi Dennis,

    No problem!! I also use something similar to you to read USB:

    Then, I use msg_in to read 640*480*2. I keep the parameters the same on the firmware side:

    usb_com_write(p_img_buf, IMG_W*IMG_H*2) where the width is 640 and the height is 480.

    You could also try referring to my code to get image data from USB to see if it makes a difference.


    Yes, my LCD screen looks white in real life, but when I take a picture with my phone, it appears a lot bluer. The same image on PC screen looks lighter. The image data should be the same though.

    When the AEC effects are on, your coffee beans image looks okay to me, while the second image looks a little greener.

    There are codes related to AEC in the firmware, but I didn't change anything.

  • Hi, Maria

    This is the figure after adjustment to AWB, and the white color seems to be OK!!

    I found that the reason is turning off the AWB, which affects the color of figure.

    Now, I use the figure to train with AWB open and AEC close.

    Thank you for helping me!

  • Hi Dennis,

    I'm glad the colors look okay now!!

    Thanks for letting us know how AWB and AEC would affect the colors, I didn't know that!

    And no problem!

The discussion has been closed due to inactivity. To continue with the topic, please feel free to post a new discussion.