-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlib_color.cpp
58 lines (40 loc) · 1.03 KB
/
lib_color.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
57
58
#include "lib_color.h"
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
/*
* class that includes some color methods
*
*
* written by Cagatay Odabasi
*
*/
using namespace std;
using namespace cv;
vector<Mat> Colorful::extractRGB(Mat im)
{
vector<Mat> channels; // create vector that contains RGB channels
split(im, channels); // split multiple channels
return channels;
}
// method to convert BGR to HSV
// and return each of HSV channels individually
std::vector<Mat> Colorful::convertBGR2HSV(cv::Mat bgr)
{
vector<Mat> hsv_channels(3);
Mat hsv;
//bgr *= 1/255;
cvtColor(bgr, hsv, CV_BGR2HSV);
split(hsv, hsv_channels);
return hsv_channels;
}
// method to convert HSV to BGR
// and returns the each BGR channel seperately
std::vector<Mat> Colorful::convertHSV2BGR(cv::Mat hsv)
{
vector<Mat> bgr_channels(3);
Mat bgr;
//bgr *= 1/255;
cvtColor(hsv, bgr, CV_HSV2BGR);
split(bgr, bgr_channels);
return bgr_channels;
}