Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Problem with HSV

$
0
0
Need some help, i am not able to find the desired contour Input: ![image description](/upfiles/148298804134565.jpg) After applying binary filter: ![image description](/upfiles/14829881046754387.jpg) After applying HSV filter: ![image description](/upfiles/14829881766591961.jpg) HSV threshold code: #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/video/video.hpp" #include "opencv2/objdetect/objdetect.hpp" #include #include #include using namespace std; using namespace cv; int main() { Size frameSize(500, 400); Mat frame = imread("C:/Proj/HSVimage.jpg", CV_LOAD_IMAGE_COLOR); Size srcSize(frame.size()); Mat hsv(srcSize, 3); vector hsvMask; Mat hImg(srcSize, 1); Mat sImg(srcSize, 1); cvtColor(frame, hsv, CV_BGR2HSV); //Vec3b hsv = hsv.at(0, 0); split(hsv, hsvMask); hImg = hsvMask[0]; sImg = hsvMask[1]; imshow("hImg", hImg); int h; for (int i = 0; i < hImg.rows; i++) { for (int a = 0; a < hImg.cols; a++) { h = hImg.at(i, a); if (h >= 0 && h <= 25) { hImg.at(i, a) = 255; } else { hImg.at(i, a) = 0; } } } imshow("HSV Image", hImg); imwrite("HSVThreshold.jpg",hImg); waitKey(0); return 0; } After thresholding the HSV image: ![image description](/upfiles/14829921799127587.jpg) Output: ![image description](/upfiles/14829882485662751.jpg) However, the desired output should have been: ![image description](/upfiles/14829882931051294.png) Need some help, this is my code for hsv: #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "iostream" using namespace cv; using namespace std; int main() { Mat image; image = imread("C:/Proj/Denoised.jpg", CV_LOAD_IMAGE_COLOR); if (!image.data) { cout << "Could not open the denoised image" << std::endl; return -1; } // Create a new matrix to hold the hsv image Mat HSV; // convert RGB image to hsv image cvtColor(image, HSV, CV_BGR2HSV); namedWindow("Display RGB image", CV_WINDOW_AUTOSIZE); imshow("Display RGB image", image); //DISPLAY image namedWindow("Result : HSV image", CV_WINDOW_AUTOSIZE); imshow("Result : HSV image", HSV); //save the HSV image imwrite("C:/Proj/HSVimage.jpg", HSV); waitKey(0); return 0; }

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>