change pixel value return false!

asked 2017-04-22 07:01:17 -0500

sabra gravatar image

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;
}
edit retag flag offensive close merge delete

Comments

2

hsv[1]<=0.4 means hsv[1]==0

LBerger gravatar imageLBerger ( 2017-04-22 07:11:09 -0500 )edit

hsv[1]/255 <0.2 ? i this right for smoke?

sabra gravatar imagesabra ( 2017-04-23 00:30:36 -0500 )edit
1

hsv is a Vec3b it is an uchar : 0, 1 2... hsv[1]/255 is always equal to 0 except for hsv[1] eqaul to255

LBerger gravatar imageLBerger ( 2017-04-23 01:31:50 -0500 )edit