Ask Your Question
0

How can correct a problem color

asked 2019-06-23 09:23:57 -0500

biza gravatar image

updated 2019-06-23 09:27:31 -0500

Hello fellows, I made a program who was responsible for detect the orange ball position inside a transparent tube , witch are limited by 2 green color lines who represent the superior and inferior tube limit. In this moment my biggest problem is put the correct color in the ball and the limits. because they vary with luminosity, can anyone help me , I share my code. thank's in advance!

<code>image description</code>

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <string>
#include <fstream>
#include <sstream>


/*#NAMESPACE*/
using namespace cv;
using namespace std;

int cntr = 0;                                                        /*VAR INCREMENT COUNT*/
int yUserMarker, yBallPosition;                                      /*INTEREST "VAR" POSITIONS*/
char str1[20];
char str2[20];

/*DEFINE*/
#define OUTPUT_WINDOW_NAME "PID CONTROLLER"                          /*DEFINE WINDOW NAME*/
#define USB_PORT_SERIAL "/dev/cu.uart-E9FF4D53F4183A34"              /*DEFINE SERIAL PORT*/

/*FUNCTION*/
void mouseMarker(int event, int x, int y, int flags, void *param);   /*USER BALL POSITION DEFENITION*/
void ballTracker(Mat& Matrix);            /*ORANGE BALL TRACKING*/
void imageMorphological(Mat& thresh);                                /*IMAGE MORPHOLOGICAL OPERATION's*/
void drawObject(int x, int y, Mat& Matrix);                          /*DRAW OUTLINE COUNTOUR's*/
string intToString(int number);                                      /*CONVERT INTEGER TO STRING*/
void regionOfInterest(Mat& frame);                                   /*DEFINE A REGION OF INTREST*/
int mousePoint(int yPoint);                                          /*MOUSE POINT*/
/*END FUNCTION*/

Point pointMarker(-10,10);                                           /*START POINT POSITION MARKER*/

/*VALUES TO SET MAX AND MIN HSV TRACK BALL*/
int H_MIN = 0;                                                      /*SET LOW BALL HUE*/
int H_MAX = 256;                                                    /*SET HIGH BALL HUE*/
int S_MIN = 0 ;                                                     /*SET LOW BALL SATURATION*/
int S_MAX = 256;                                                    /*SET HIGH BALL SATURATION*/
int V_MIN = 0;                                                      /*SET LOW BALL VALUE*/
int V_MAX = 256;                                                    /*SET HIGH BALL VALUE*/

int retorno = 0;


/*VALUES FOR THE ROI*/
int hueValue = 120;
int hueRange = 10;
int minSaturation = 90;
int minValue = 90;


int main(int argc, char** argv) {
    /*SERIAL TO ARDUINO GLOBAL DECLARATIONS*/
    fstream MSP430;
    MSP430.open(USB_PORT_SERIAL);
    /*VERIFY IF THE SERIAL PORT IS CONNECTED OR NOT*/
    if (MSP430.fail()) {
        /*FILE COULD NOT BE OPENED*/
        cout << "SERIAL OPEN FAILED" << endl;
    }else{
        cout << "SERIAL OPEN SUCESSEFUL" << endl;
    }
    /*CAMERA CAPTURE*/
    VideoCapture cap(0);
    /*MATRIX LINE LIMITS*/
    Mat limits;
    /*MATRIX STORAGE IMAGE CAMERA */
    Mat cameraFrame;
    /*VERIFY IF EXISTS ANY CAMERA*/

    if(!cap.isOpened()){
        cout << "CAMERA CAPTURE FAILED" << endl;
        retorno = 1;
    }
    cout << "CAMERA OPENED SUCCESSFULLY" << endl;

    /*DEFINE IMAGE SIZE AND NAME*/
    namedWindow(OUTPUT_WINDOW_NAME, WINDOW_NORMAL);   /*CREATE A NEW WINDOW*/




    while(true){

        cap >> cameraFrame;
        Mat Matrix = cameraFrame;
        Mat mask;

        /*SHOW MOUSE EVENT SET POINT*/
        if(pointMarker.x!=-1){
            drawMarker(Matrix, pointMarker, Scalar(0,0,255),MARKER_CROSS, 10, 1);
        }
        /*CALL MOUSE EVENT*/
        setMouseCallback(OUTPUT_WINDOW_NAME,  mouseMarker, (void*)(&pointMarker));
        /*LIMITS*/
        regionOfInterest(Matrix);
        /*TRACKING BALL*/
        ballTracker(Matrix);
        /*VALUES STREAM TO ARDUINO*/
        stringstream  yMarker, yPosition;

        yMarker << yUserMarker;
        yPosition << yBallPosition;

        rectangle(Matrix,Point(0, 670), Point(220,720), Scalar(0, 0, 0), -1);

        sprintf(str1,"SET  POINT: %d",yUserMarker);
        sprintf(str2,"BALL POINT: %d",yBallPosition);

        putText(Matrix, str1, Point2f(20,690), FONT_HERSHEY_PLAIN, 1,  Scalar(0,249,158,51),1);
        putText(Matrix, str2, Point2f(20,710), FONT_HERSHEY_PLAIN, 1,  Scalar(0,249,158,51),1);


       // cout << ...
(more)
edit retag flag offensive close merge delete

Comments

I am not quite sure what you mean by " put the correct color in the ball and the limits. because they vary with luminosity"

Can you explain this more? Also, can you share some sample images with us?

Chris gravatar imageChris ( 2019-06-23 14:55:25 -0500 )edit

ok i will try to share some pictures. I have defined a superior and inferior limit . I need implement a ROI between the two limits, but i can't recognize the two green lines who delimit the limits. this two lines are static's always at same distance, there is a way to recognize in the first camera capture this limits, avoiding the continuous processing and recognition of the lines?

biza gravatar imagebiza ( 2019-06-23 16:21:39 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-06-24 04:18:35 -0500

kbarni gravatar image

Having a real image could help to give a good answer. Here are some ideas:

  • If you worry about the luminosity, use a luminosity invariant color space (e.g. HSV). Then use a segmentation on the hue and saturation channel (inRange function) to detect the ball and the lines:

    imageHSV = cvtColor(image,COLOR_BGR2HSV);
    ball = inRange(imageHSV,Scalar(20,100,100),Scalar(30,255,255)); //you have to define the values yourself
    lines = inRange(imageHSV,Scalar(50,100,100),Scalar(70,255,255));
    
  • for the green lines, use a horizontal integration on the segmented image (if the tube is always vertical) or a contour detection to get the position of the limits. Same for the ball.

  • you can recognize the limits once (if the tube is static) or in every frame. Normally the operation is fast, so it won't pose any problems for real time processing.
edit flag offensive delete link more

Comments

Hello my friend thank's for answering. yes I now to perform this i have to use luminosity invariant color space (HSV), and that is I have done... for the ball:

inRange(imgHSV, Scalar(16,155,155), Scalar(40, 255, 255), imgThreshLow);
inRange(imgHSV, Scalar(95, 155, 155),Scalar(120, 255, 255), imgThreshHigh);

add(imgThreshLow,imgThreshHigh,imageThreshold);

GaussianBlur(imageThreshold, imageThreshold, Size(3,3), 0);

and, for the lines

 inRange(hueImage, hueValue - hueRange, hueValue + hueRange, hueMask);

like you can see before in my code. Can you show me a way to perform a recognise of the limit once, to not preform this operation any more times

biza gravatar imagebiza ( 2019-06-24 10:25:48 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-06-23 09:23:57 -0500

Seen: 54 times

Last updated: Jun 24