C++ OpenCV Color Thersholding HSV images Errors

662 views Asked by At

So basically Im trying to detect a green target using Canny edge detection and color threshold. The original image as shown below is an example of what im trying to detect.

Original Image:

Original Image

After applying canny edge detection this is what appears.

CannyEdge Image:

CannyEdge Image

From here I want only the green rectangle targets to appear so I use the inRange function and input the ranges of HSV I got from GIMP of that certain green target in that picture. However I divded the Hue value by 2 as I heard that OpenCV uses Hue values 0 - 180 unlike GIMP which uses 0 - 360 and still end up with a black output image from the inRange function....

How do you only make the green rectangles appear?

#include <opencv2/opencv.hpp>
#include <iostream>


using namespace cv;

Mat ORIGINAL_img;
Mat HSV_img, FINAL_img, MASKED_img, BLURRED_img;

Mat dst, detectededges;





int main() {


    ORIGINAL_img = imread("straight7.jpg", CV_LOAD_IMAGE_COLOR);


    cvtColor(ORIGINAL_img, HSV_img, COLOR_BGR2HSV);
    inRange(HSV_img, Scalar(80, 150, 15), Scalar(100, 255, 60), MASKED_img);
    blur(MASKED_img, BLURRED_img, Size(3,3));
    Canny(BLURRED_img, detectededges, 50, 20, 3);
    dst = Scalar::all(0);
    HSV_img.copyTo(dst, detectededges);


    imwrite("cannyoutput.jpg", dst);
    imwrite("colormaskoutput.jpg", MASKED_img);


    //imshow("color", HSV_img);
    waitKey(0);

    return 0;
}
0

There are 0 answers