1 #include "opencv2/opencv.hpp"
11 cv::Mat fit(const cv::Mat &img) {
14 int height = img.rows;
15 double size, width_small, height_small;
16 if (width >= height) {
17 size = width_small = (rings * 2) / sqrt(2);
18 height_small = width_small * ((double) height / (double) width);
20 size = height_small = (rings * 2) / sqrt(2);
21 width_small = height * (width / (double) height);
23 resize(img, out, Size((int) width_small, (int) height_small));
24 int top = (size - height_small) / 2;
25 int down = (size - height_small + 1) / 2;
26 int left = (size - width_small) / 2;
27 int right = (size - width_small + 1) / 2;
28 cv::copyMakeBorder(out, out, top, down, left, right, cv::BORDER_CONSTANT,
32 cv::Mat crop(const cv::Mat &img) {
35 int height = img.rows;
37 if (width >= height) {
39 Size(((double) rings * 2 * width) / (double) height,
41 int mid = (out.cols - (rings * 2)) / 2;
42 crop = cv::Rect(mid, 0, rings * 2, rings * 2);
46 ((double) rings * 2 * height) / (double) width));
47 int mid = (out.rows - (rings * 2)) / 2;
48 crop = cv::Rect(0, mid, rings * 2, rings * 2);
52 double to_rad(double degree) {
53 double pi = 3.14159265359;
54 return (degree * (pi / 180));
56 int main(int argc, char **argv) {
57 VideoCapture cap(argv[1]);
59 if (!cap.isOpened()) {
60 cout << "Error opening video stream or file" << endl;
75 Mat image = Mat(rings * 2, rings * 2, frame.type(), double(0));
77 Vec3b buffer[deg][rings] = { 0 };
78 for (int d = 0; d < deg; d++) {
79 for (int radius = 0; radius < rings; radius++) {
81 cos(to_rad((double) d / (deg / 360))) * radius);
83 sin(to_rad((double) d / (deg / 360))) * radius);
84 if (abs(x) >= frame.cols / 2 || abs(y) >= frame.rows / 2)
85 buffer[d][radius] = 0;
87 buffer[d][radius] = frame.at < Vec3b
88 > (x + frame.cols / 2, y + frame.rows / 2);
91 for (int d = 0; d < deg; d++) {
92 for (int radius = 0; radius < rings; radius++) {
94 sin(to_rad((double) d / (deg / 360))) * radius);
96 cos(to_rad((double) d / (deg / 360))) * radius);
98 > (Point(x + image.cols / 2, y + image.rows / 2)) =
102 for (int d = 0; d < deg; d++) {
103 int y = (int) round(sin(to_rad((double) d / (deg / 360))) * rings);
104 int x = -(int) round(cos(to_rad((double) d / (deg / 360))) * rings);
105 image.at < Vec3b > (Point(x + image.cols / 2, y + image.rows / 2)) =
106 Vec3b(255, 255, 255);
109 resize(image, image, Size(), 500 / (rings * 2), 500 / (rings * 2));
110 imshow("Frame", image);
112 char c = (char) waitKey(25);