Posts

Showing posts with the label Hsv

Convert HSV To Grayscale In OpenCV

Answer : The conversion from HSV to gray is not necessary: you already have it. You can just select the V channel as your grayscale image by splitting the HSV image in 3 and taking the 3rd channel: Mat im = imread("C:/local/opencv248/sources/samples/c/lena.jpg", CV_LOAD_IMAGE_COLOR); Mat imHSV; cvtColor(im, imHSV, CV_BGR2HSV); imshow("HSV", imHSV); //cvtColor(imHSV, imHSV, CV_BGR2GRAY); Mat hsv_channels[3]; cv::split( imHSV, hsv_channels ); imshow("HSV to gray", hsv_channels[2]); imshow("BGR", im); cvtColor(im, im, CV_BGR2GRAY); imshow("BGR to gray", im); waitKey(); hsv1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2HSV) h, s, v1 = cv2.split(hsv1) cv2.imshow("gray-image",v1)