Ask Your Question

Mihnea's profile - activity

2020-10-21 05:35:51 -0600 received badge  Student (source)
2018-06-02 11:55:10 -0600 received badge  Notable Question (source)
2017-08-24 18:37:48 -0600 received badge  Popular Question (source)
2015-03-16 07:38:17 -0600 received badge  Self-Learner (source)
2015-03-14 15:47:03 -0600 commented answer How could i detect a color?

Here is the histogram of hue image description

I have too many pixels of red that aren't from bands of the resistor. I cant say where is the red one. With yellow works. What can i do?

2015-03-14 12:10:17 -0600 commented answer How could i detect a color?

I know i need to give a interval because i cant get the "pure" red or blue from image. If i get the hue values and plot them as graph i get a histogram. From level of the hue histogram i can identify the color?

2015-03-14 11:36:56 -0600 received badge  Organizer (source)
2015-03-14 11:25:26 -0600 asked a question How could i detect a color?

Hello!

I want to make a program that detects the value o a resistor by color code. I made the program like this

  1. In the center of the frame i draw a rectangle
  2. At the middle of the rectangle i draw a line
  3. I get all the pixel from the line and store them RGB value in a vector
  4. I need to detect the color bars from the resistor

I tried to compare the RGB values of red,yellow etc to the RGB values of my pixles from the frame .

Mat src,dst;

dst=imread("D:\\image2.bmp",CV_LOAD_IMAGE_COLOR);
src=dst.clone();
Size matSize=src.size();
Point center(matSize.width/2,matSize.height/2);
Point pt1(0,matSize.height/2);
Point pt2(matSize.width,matSize.height/2);
line(src,pt1,pt2,Scalar(0,0,255),1,8,0);
rectangle(src,Point(center.x-matSize.width/6,center.y-matSize.height/4),Point(center.x+matSize.width/6,center.y+matSize.height/4),Scalar(0,0,255),1,8,0);
circle(src,center,2,Scalar(255,255,0),1,8,0);


//points for line of scanning

Point ptScan1(center.x-matSize.width/6,center.y);
Point ptScan2(center.x+matSize.width/6,center.y);
circle(src,ptScan1,2,Scalar(255,255,0),1,8,0);
circle(src,ptScan2,2,Scalar(255,255,0),1,8,0);

//parcurgere linie de scanare
vector<Point3i> bgr_planes;
int codesview[10][30]   = { { 0, 0, 0 }, // black
        { 139, 69, 19 }, // brown
        { 255, 0, 0 }, // red
        { 255, 128, 0 }, // orange
        { 255, 255, 0 }, // yellow
        { 0, 255, 0 }, // green
        { 0, 0, 255 }, // blue
        { 200, 0, 255 }, // violet
        { 128, 128, 128 }, // gray
        { 255, 255, 255 }       // white
};

Point3i black(0,0,0);
Point3i brown(139,69,19);
Point3i red(255,0,0);
Point3i orange(255,128,0);
Point3i yellow(255,255,0);
Point3i green(0,255,0);
Point3i blue(0,0,255);
Point3i violet(200,0,255);
Point3i gray(128,128,128);
Point3i white(255,255,255);

for(int i=ptScan1.x;i<ptScan2.x;i++)
{
    Vec3b intensity = dst.at<Vec3b>(center.y, i);
    bgr_planes.push_back(Point3f(intensity.val[0],intensity.val[1],intensity.val[2]));
    //printf("%d %d %d\n",intensity.val[0],intensity.val[1],intensity.val[2]);
}

for (int i=0;i<bgr_planes.size();i++)
{
    printf("b=%d g=%d r=%d \n",bgr_planes[i].x,bgr_planes[i].y,bgr_planes[i].z);

        if (bgr_planes[i].x==0 && bgr_planes[i].y==0 && bgr_planes[i].z==255)
        {printf("blue\n");}
        else
        if (bgr_planes[i].x==139 && bgr_planes[i].y==69 && bgr_planes[i].z==19)
        {printf("brown\n");}
        else
        if (bgr_planes[i].x==255 && bgr_planes[i].y==0 && bgr_planes[i].z==0)
        {printf("red\n");}
        else
        if (bgr_planes[i].x==255 && bgr_planes[i].y==128 && bgr_planes[i].z==0)
        {printf("orange\n");}
        else
        if (bgr_planes[i].x==200 && bgr_planes[i].y==0 && bgr_planes[i].z==255)
        {printf("violet\n");}
        else
        if (bgr_planes[i].x==0 && bgr_planes[i].y==0 && bgr_planes[i].z==255)
        {printf("blue\n");}
        else
        if (bgr_planes[i].x==0 && bgr_planes[i ...
(more)