HomeProgrammingConvert RGB to HSV and back with a micro controller

Comments

Convert RGB to HSV and back with a micro controller — 4 Comments

  1. Since this is one of the popular search results, I’ll provide some informations on opencv. The images are internaly stored as arrays. For regular image, it’s RGB format, RGBA or some more exotic. To extract regular RGB, you can use this code:

    Mat image = imread(“input.jpg”, CV_LOAD_IMAGE_COLOR); // Or whatever settings
    if (!image.data) { // Valid image
    byte[] data = image.data; // Pixel array
    unsigned int totalPixels = image.rows*image.cols;
    struct RGB_set RGB; // RGB structure
    struct HSV_set HSV; // HSV structure
    for(int i=0;i<totalPixels;i++) { // For every pixel in image
    RGB.r = input_data[(i * 3) + 2];
    RGB.g = input_data[(i * 3) + 1];
    RGB.b = input_data[(i * 3) ];
    printf ("Yellow in RGB: %X, %X, %X\n", RGB.r, RGB.g, RGB.b);
    RGB2HSV(RGB, &HSV);
    printf ("converted to HSV: %X, %X, %X\n", HSV.h, HSV.s, HSV.v);
    }
    }

  2. I was searching for a simple, straightforward function to convert RGB vales to HSV, and you provided it.

    The code worked faultlessly without any modification in the Arduino IDE. Just what I was looking for, Thank You!

    If I end up using your code in a project I plan on sharing in a YouTube video, I will definitely be crediting you, and providing a link to this page.

  3. dear sir
    i need help how to convert rgb to hsv in opencv,tell me sir what are the changes have to made for the above code

    • I am sorry, but I don’t have or use the opencv library! I would expect it already has functions for this very trivial conversions. Else make your own function with your code.

Leave a Reply to satish Cancel reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.