How can correct a problem color
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!
#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 << ...
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?
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?