-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcolor_cycle.cpp
More file actions
36 lines (28 loc) · 909 Bytes
/
color_cycle.cpp
File metadata and controls
36 lines (28 loc) · 909 Bytes
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
#include <opencv2/imgproc.hpp>
#include "color_cycle.h"
cv::Mat3b hsv;
int accHOffset = 0;
namespace color_cycle
{
void rotate_hue(cv::Mat3b const& img, cv::Mat3b& result_img, int hsteps)
{
assert(result_img.size() == img.size() && result_img.type() == img.type());
// re-allocate global temp storage if needed
hsv.create(img.size());
// convert to HSV
cv::cvtColor(img, hsv, CV_BGR2HSV_FULL);
for (int r = 0; r < hsv.rows; ++r)
for (int c = 0; c < hsv.cols; ++c)
hsv.at<cv::Vec3b>(r, c)[0] = (hsv.at<cv::Vec3b>(r, c)[0] + accHOffset) % 255; // cycle H
// convert back to BGR
cv::cvtColor(hsv, result_img, CV_HSV2BGR_FULL);
// update cycle offset
accHOffset += hsteps;
}
void clear_all()
{
// release global memory
hsv.release();
accHOffset = 0;
}
}