Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

change pixel value return false!

i have a program that check values of pixels to be in range

but the result surprize me!

only just part of image affected and smoky area arnt in range!

please help me

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


using namespace std;
using namespace cv;

void colorDetect(Mat mFrame,int redThreshold, double saturationThreshold)
{
    Mat temp;
    GaussianBlur(mFrame, temp, Size(3, 3), 0);
    Mat img;
    cvtColor(temp,img,CV_BGR2HSV);


    for (int i = 0; i < temp.rows; i++) {
        for (int j = 0; j < temp.cols; j++) {


            Vec3b& hsv = img.at<Vec3b>(i, j);

            Vec3b& v = temp.at<Vec3b>(i, j);

                    if((abs(v[2]-v[1])<=20 && abs(v[0]-v[1])<=20 && abs(v[2]-v[0])<=20 && hsv[1]<=0.4)  ){
                        mFrame.at<uchar>(i, j) = 255;

                    }
                    else{

                        mFrame.at<uchar>(i, j) = 0;
                    }


        }
    }

    imshow("mframe",mFrame);
    cvWaitKey(0);
}

int main(){

    Mat frame=imread("D:/121.jpg",1);
    colorDetect(frame,150,0.12);


    return 1;
}