Ask Your Question
0

i want to convert from rgb to lab

asked 2014-02-04 05:13:57 -0600

amin.karimi gravatar image

updated 2014-02-05 03:57:28 -0600

this is my code and my goal is to convert from rgb to lab but when implement this alghoritm opencv produce error and does'nt answer why?

Mat image,im;   
image=imread("2.jpg");  
a=image.rows;   
b=image.cols;   
cvtColor(image,im,CV_BGR2Lab);
imshow("sohi",im);
edit retag flag offensive close merge delete

Comments

What kind of error?

Bartis Áron gravatar imageBartis Áron ( 2014-02-04 05:18:21 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2014-02-05 04:06:36 -0600

Okay, this code snippet works perfectly on my system - just tested it

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;
using namespace std;

int main()
{
    Mat image, image_out;
    image=imread("/home/steven/Documents/test.jpg");
    cvtColor(image, image_out, CV_BGR2Lab);
    imshow("sohi",image_out); waitKey(0);
    return 0;
}

So I am guessing you are either in one of the following problems

  • You are linking against the wrong libraries or to no libraries at all in linker options
  • Your image is not in the directory you are building, try to use absolete paths and not relative ones like I did
  • You forgot to place a waitKey() after the imshow and by that, there is no resulting frame. This is quite normal since the waitKey() holds the window and gives it the chance to call its internal redraw function. An imshow always needs to be accompagnied by this. Giving it the value 0 will wait until a key is hit, else the time is in milliseconds.
edit flag offensive delete link more

Comments

i copy your code in my visual but it produce error like my code : no source avilable and write SEH Exception was handled

amin.karimi gravatar imageamin.karimi ( 2014-02-05 08:21:11 -0600 )edit

You need to change the actual location of the image .. also make sure your environment is configured correctly.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-05 08:26:12 -0600 )edit

steven i copy my image to location of project and always do this work. so this is not problem and a lots of program i write with visual and so my configure is not problem too, i dont know?

amin.karimi gravatar imageamin.karimi ( 2014-02-05 09:50:06 -0600 )edit

Your remark doesn't make anything more clear. Stop placing images in project location but use an absolete path to it. See if that works out first please. Also, grab screens of your complete configuration and add them to your post using the edit button...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-06 03:26:49 -0600 )edit

oh i know my problem was image type , my image type was bmp and i write jpg . thanks steven . steven open cv has not rgb to hsi ?why?

amin.karimi gravatar imageamin.karimi ( 2014-02-06 09:01:07 -0600 )edit

Because it is a very simple thing to apply. Calculate the HSV channels, then do a simple average of the three color channels and use that average as your I channel.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-06 09:13:15 -0600 )edit

Question Tools

Stats

Asked: 2014-02-04 05:13:57 -0600

Seen: 17,330 times

Last updated: Feb 05 '14