44 lines
850 B
C++
44 lines
850 B
C++
|
|
#include <opencv2/core.hpp>
|
||
|
|
#include <opencv2/highgui.hpp>
|
||
|
|
#include <opencv2/imgproc.hpp>
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
using namespace cv;
|
||
|
|
|
||
|
|
int main(){
|
||
|
|
Mat img = imread("milka.jpg", IMREAD_COLOR);
|
||
|
|
Mat hsv;
|
||
|
|
Mat dest;
|
||
|
|
Mat dest2;
|
||
|
|
|
||
|
|
cvtColor(img, hsv, COLOR_BGR2HSV);
|
||
|
|
Mat_<Vec3b> hs = hsv;
|
||
|
|
Vec3b c;
|
||
|
|
|
||
|
|
for(int i = 0; i < img.rows; i++){
|
||
|
|
for(int j = 0; j < img.cols; j++){
|
||
|
|
c = hsv.at<Vec3b>(i,j);
|
||
|
|
if(c[0] > 120){
|
||
|
|
hsv.at<Vec3b>(i,j)[0] = 0; //h csatornan mindent 0-ra szinezunk
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
for(auto& c : hs){
|
||
|
|
if(c[0] > 120){
|
||
|
|
c[0] = 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
cvtColor(hsv, dest, COLOR_HSV2BGR);
|
||
|
|
cvtColor(hs, dest2, COLOR_HSV2BGR);
|
||
|
|
imshow("img", img);
|
||
|
|
imshow("hsv", dest);
|
||
|
|
imshow("hs", dest2);
|
||
|
|
|
||
|
|
|
||
|
|
waitKey();
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|