-
Notifications
You must be signed in to change notification settings - Fork 1
/
hsvFinder.cpp
56 lines (42 loc) · 1.31 KB
/
hsvFinder.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Author: Liam Lawrence
* Date: 2.20.17
*
* Finds HSV Values of the selected pixel
*/
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
cv::Mat frame,
hsvFrame;
void CallBackFunc(int event, int x, int y, int flags, void* userdata){
if(event == cv::EVENT_LBUTTONDOWN) {
// Converts the BGR stream to HSV
cvtColor(frame, hsvFrame, CV_BGR2HSV);
// Grabs the HSV color values out of the spot we clicked on
cv::Vec3b hsv = hsvFrame.at<cv::Vec3b>(y, x);
int hue = hsv.val[0];
int saturation = hsv.val[1];
int value = hsv.val[2];
std::cout << "H: " << hue << "\nS: " << saturation << "\nV: " << value << "\n------\n";
}
}
int main() {
// Connects to our camera
cv::VideoCapture cap(0);
// Initial print to keep things pretty
std::cout << "------\n";
// Creates Window
cv::namedWindow("HSV Grabber", CV_WINDOW_AUTOSIZE);
for(;;) {
// Grabs frame and converts its to HSV
cap.read(frame);
// If we click, grab the color values
cv::setMouseCallback("HSV Grabber", CallBackFunc, NULL);
// Shows frame on window
imshow("HSV Grabber", frame);
// Hit ESC to quit
if(cv::waitKey(1) == 27)
break;
}
}