{"id":357910,"date":"2024-05-21T00:00:33","date_gmt":"2024-05-21T00:00:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=357910"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=357910","title":{"rendered":"<span>\u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432\u0438\u0434\u0435\u043e \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u043e\u043f\u0440\u043e\u0431\u0443\u044e OpenCV, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u0438\u0434\u0435\u043e, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 &#8212; \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438 ASCII \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0432\u0438\u0434\u0435\u043e\u0440\u043e\u043b\u0438\u043a \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b. <\/p>\n<p><span class=\"habrahidden\">\u0422\u0435, \u043a\u0442\u043e \u0435\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c, \u043c\u043e\u0433\u0443\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044f \u0437\u0430\u0431\u0438\u0432\u0430\u044e \u0434\u0440\u0435\u043b\u044c\u044e \u0433\u0432\u043e\u0437\u0434\u0438 &#8212; \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u043e\u043d\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0433\u043e \u0437\u0440\u0435\u043d\u0438\u044f.<\/span><\/p>\n<h2>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u043e\u043d \u0432\u043f\u043e\u043b\u043d\u0435 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u0435\u043d:<\/h2>\n<ol>\n<li>\n<p>\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0432\u0438\u0434\u0435\u043e<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043a\u0430\u0434\u0440\u043e\u0432\u043e \u043f\u043e \u043d\u0435\u043c\u0443 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u0441\u044f, \u043f\u043e\u043a\u0430 \u043a\u0430\u0434\u0440\u044b \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0430\u0442\u0441\u044f, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u0430\u0434\u0440\u0430:<\/p>\n<ol>\n<li>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u0421\u043a\u0435\u0439\u043b\u0438\u043c \u0435\u0433\u043e \u0434\u043e \u043d\u0443\u0436\u043d\u044b\u0445 \u043d\u0430\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 (\u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0438\u043a\u0441\u0435\u043b\u0438 \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e, \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u044f:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u044c<\/p>\n<\/li>\n<li>\n<p>\u0421\u0442\u0430\u0432\u0438\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0435\u0433\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u0438 \u0441\u0438\u043c\u0432\u043e\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u0441\u0445\u043e\u0436\u0443\u044e \u044f\u0440\u043a\u043e\u0441\u0442\u044c (\u0431\u043e\u043b\u0435\u0435 \u044f\u0440\u043a\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b &#8212; \u0437\u043d\u0430\u0447\u0438\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439) <\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>\u0412\u044b\u0432\u043e\u0434\u0438\u043c \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u043a\u0443<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h2>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0434\u0435\u043b\u0443:<\/h2>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432.<\/p>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, ncurses \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c (\u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u0435\u0437 \u043d\u0435\u0433\u043e): <\/p>\n<pre><code class=\"cpp\">#include &lt;chrono> #include &lt;iostream> #include &lt;opencv2\/opencv.hpp> #include &lt;opencv2\/videoio.hpp> #include &lt;string> #include &lt;thread> \/\/ \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u044b chrono \u0438 thread :D?  \/\/ \u0421\u0438\u0448\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435 \u043f\u043b\u044e\u0441\u043e\u0432\u044b\u0445 #include &lt;curses.h> #include &lt;ncurses.h><\/code><\/pre>\n<p>\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0432\u0438\u0434\u0435\u043e \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 VideoCapture, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u0432\u0438\u0434\u0435\u043e:<\/p>\n<pre><code class=\"cpp\">cv::VideoCapture video_capture(\"\/path\/to\/video\")); if (!video_capture.isOpened()) {     std::cerr &lt;&lt; \"Failed to open video file.\\n\";     return -1;   } <\/code><\/pre>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b:<\/p>\n<pre><code class=\"cpp\">\/\/ \u042d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u044d\u0444\u0438\u0446\u0435\u043d\u0442  \/\/ \u043d\u0443\u0436\u043d\u044b\u0439 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0440\u043e\u043d \u0432\u0438\u0434\u0435\u043e \u043f\u0440\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043a\u0435\u0439\u043b\u0435  \/\/ \u043c\u043e\u0435\u0439 \u043a\u043e\u043d\u0441\u043e\u043b\u0438   const float correction_factor = 4.75;  \/\/ \u041e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0431\u0443\u0434\u0435\u043c 10 \u0440\u0430\u0437 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \/\/ \u0438\u043d\u0430\u0447\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0442\u0430\u0439\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0448\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u0432\u0438\u0434\u0435\u043e   const int targetfps = 10;   const int fps = video_capture.get(cv::CAP_PROP_FPS);   const int fpsdif = fps \/ targetfps;   const int frame_duration = 1000 \/ fps;  \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0432\u0438\u0434\u0435\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u0445, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d   const int frame_width = video_capture.get(cv::CAP_PROP_FRAME_WIDTH);   const int frame_height = video_capture.get(cv::CAP_PROP_FRAME_HEIGHT);   const int screen_height = 120;   const int screen_width =       screen_height * (frame_width \/ frame_height) * correction_factor;<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b, \u0441\u043e\u043e\u0442\u0432. \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u0438\u043a\u0441\u0435\u043b\u044f (\u043e\u043d\u0430 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442 0 \u0434\u043e 255):<\/p>\n<pre><code class=\"cpp\"> const char get_ASCII_from_pixel(const int pixelintensity) {   \/\/ \u0412\u044b\u0431\u043e\u0440 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u0435\u043d, \u043c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0442\u0430\u043a   std::string chars_by_brightness = \"$@B%8&amp;#*\/|(-_+;:,.  \";   \/\/ \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c   std::reverse(chars_by_brightness.begin(), chars_by_brightness.end());       return chars_by_brightness[static_cast&lt;float>(pixelintensity *                                                 chars_by_brightness.length()) \/                              256.f]; }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 \u0446\u0438\u043a\u043b\u0443:<\/p>\n<pre><code class=\"cpp\"> \/\/ \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u043a\u0430\u0434\u0440\u0430,  \/\/ \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0447\u0435\u0441\u0442\u044c \u0435\u0433\u043e \u0438\u0437 \u0444\u0440\u0435\u0439\u043c\u0442\u0430\u0439\u043c\u0430   int starttime = 0, endtime = 0, framedrawtime = 0, i = 0;  \/\/ \u041e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0446\u0438\u043a\u043b\u0435 \/\/ cv::Mat - \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 n-\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \/\/ \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043a\u0430\u0434\u0440 (\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b - \u043f\u0438\u043a\u0441\u0435\u043b\u0438)   cv::Mat original_frame, grayscaled_frame, grayscaled_resized_frame;    initscr(); \/\/ \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0432 curses \u0440\u0435\u0436\u0438\u043c   for (;;) {     \/\/ \u0437\u0430\u0441\u0435\u043a\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u044f     starttime = std::chrono::duration_cast&lt;std::chrono::milliseconds>(                     std::chrono::system_clock::now().time_since_epoch())                     .count();          \/\/ \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u0434\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u043c     i = fpsdif;     while (--i) {       video_capture.grab();     }      \/\/ \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 >> \u0443 cv::VideoCapture \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0430\u0434\u0440     video_capture >> original_frame;      \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u0432\u0438\u0434\u0435\u043e     if (original_frame.empty())       break;      \/\/ \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443     cv::cvtColor(original_frame, grayscaled_frame, cv::COLOR_BGR2GRAY);     cv::resize(grayscaled_frame, grayscaled_resized_frame,                cv::Size(screen_width, screen_height), 0, 0, cv::INTER_LINEAR);      for (int x = 0; x &lt; screen_height; ++x) {       for (int y = 0; y &lt; screen_width; ++y) {         \/\/ \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c \u043a\u0430\u0440\u0435\u0442\u043a\u0443 curses \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0442\u0443\u0434\u0430 \u0441\u0438\u043c\u0432\u043e\u043b         mvaddch(x, y,                 get_ASCII_from_pixel(grayscaled_resized_frame.at&lt;uchar>(x, y)));       }     }      \/\/ \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438     refresh();         endtime = std::chrono::duration_cast&lt;std::chrono::milliseconds>(                   std::chrono::system_clock::now().time_since_epoch())                   .count();          \/\/ \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0448\u043b\u043e \u0443\u0436\u0435     framedrawtime = endtime - starttime;      \/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u043b\u0438\u0442\u0441\u044f \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e     std::this_thread::sleep_for(         std::chrono::milliseconds(fpsdif * frame_duration - framedrawtime));   }    endwin(); \/\/ \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 curses \u0440\u0435\u0436\u0438\u043c\u0430<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0412\u0435\u0441\u044c \u043a\u043e\u0434: <\/summary>\n<div class=\"spoiler__content\">\n<p>src\/main.cpp<\/p>\n<pre><code class=\"cpp\">#include &lt;chrono> #include &lt;iostream> #include &lt;opencv2\/opencv.hpp> #include &lt;opencv2\/videoio.hpp> #include &lt;string> #include &lt;thread>  #include &lt;ncurses.h>  const std::string getpathto(const char *file) {   std::stringstream ss;   ss &lt;&lt; RESOURCES_PATH &lt;&lt; file;   return ss.str(); }  const char get_ASCII_from_pixel(const int pixelintensity) {   std::string chars_by_brightness = \"$@B%8&amp;#*\/|(-_+;:,.  \";   std::reverse(chars_by_brightness.begin(), chars_by_brightness.end());   return chars_by_brightness[static_cast&lt;float>(pixelintensity *                                                 chars_by_brightness.length()) \/                              256.f]; }  int main() {   cv::VideoCapture video_capture(getpathto(\"vid1.mp4\"));    if (!video_capture.isOpened()) {     std::cerr &lt;&lt; \"Failed to open video file.\\n\";     return -1;   }    const float correction_factor = 4.75;   const int targetfps = 10;   const int fps = video_capture.get(cv::CAP_PROP_FPS);   const int fpsdif = fps \/ targetfps;   const int frame_duration = 1000 \/ fps;   const int frame_width = video_capture.get(cv::CAP_PROP_FRAME_WIDTH);   const int frame_height = video_capture.get(cv::CAP_PROP_FRAME_HEIGHT);   const int screen_height = 120;   const int screen_width =       screen_height * (frame_width \/ frame_height) * correction_factor;    int starttime = 0, endtime = 0, framedrawtime = 0, i = 0;   cv::Mat original_frame, grayscaled_frame, grayscaled_resized_frame;    initscr();   for (;;) {     starttime = std::chrono::duration_cast&lt;std::chrono::milliseconds>(                     std::chrono::system_clock::now().time_since_epoch())                     .count();     i = fpsdif;     while (--i) {       video_capture.grab();     }      video_capture >> original_frame;     if (original_frame.empty())       break;      cv::cvtColor(original_frame, grayscaled_frame, cv::COLOR_BGR2GRAY);     cv::resize(grayscaled_frame, grayscaled_resized_frame,                cv::Size(screen_width, screen_height), 0, 0, cv::INTER_LINEAR);      for (int x = 0; x &lt; screen_height; ++x) {       for (int y = 0; y &lt; screen_width; ++y) {         mvaddch(x, y,                 get_ASCII_from_pixel(grayscaled_resized_frame.at&lt;uchar>(x, y)));       }     }      refresh();      endtime = std::chrono::duration_cast&lt;std::chrono::milliseconds>(                   std::chrono::system_clock::now().time_since_epoch())                   .count();      framedrawtime = endtime - starttime;      std::this_thread::sleep_for(         std::chrono::milliseconds(fpsdif * frame_duration - framedrawtime));   }    endwin();    return 0; } <\/code><\/pre>\n<p>CMakeLists.txt<\/p>\n<pre><code class=\"cmake\">cmake_minimum_required(VERSION 3.25) project(ASCII_video) set(OpenCV_DIR \/usr\/lib\/opencv4\/opencv2) find_package(OpenCV REQUIRED) find_package(Curses REQUIRED) # find_package(VTK REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS} ${CURSES_INCLUDE_DIR})  add_executable(MyExecutable src\/main.cpp)  target_link_libraries(MyExecutable ${OpenCV_LIBS} ${VTK_LIBRARIES} ${CURSES_LIBRARIES}) target_compile_definitions(MyExecutable PUBLIC RESOURCES_PATH=\"${CMAKE_CURRENT_SOURCE_DIR}\/resources\/\")  <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u0418\u0442\u043e\u0433:<\/h2>\n<p>\u0412\u0438\u0434\u0435\u043e:<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/655f25bb3eb8e176bff28d96\" data-style=\"\" id=\"655f25bb3eb8e176bff28d96\" width=\"\"><\/div>\n<p>\u041e\u043d\u043e \u0436\u0435, \u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438:<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/655f25c93add7830898fcbe9\" data-style=\"\" id=\"655f25c93add7830898fcbe9\" width=\"\"><\/div>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/768456\/\"> https:\/\/habr.com\/ru\/articles\/768456\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u043e\u043f\u0440\u043e\u0431\u0443\u044e OpenCV, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u0438\u0434\u0435\u043e, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 &#8212; \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438 ASCII \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0432\u0438\u0434\u0435\u043e\u0440\u043e\u043b\u0438\u043a \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b. <\/p>\n<p><span class=\"habrahidden\">\u0422\u0435, \u043a\u0442\u043e \u0435\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c, \u043c\u043e\u0433\u0443\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044f \u0437\u0430\u0431\u0438\u0432\u0430\u044e \u0434\u0440\u0435\u043b\u044c\u044e \u0433\u0432\u043e\u0437\u0434\u0438 &#8212; \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u043e\u043d\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0433\u043e \u0437\u0440\u0435\u043d\u0438\u044f.<\/span><\/p>\n<h2>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u043e\u043d \u0432\u043f\u043e\u043b\u043d\u0435 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u0435\u043d:<\/h2>\n<ol>\n<li>\n<p>\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0432\u0438\u0434\u0435\u043e<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043a\u0430\u0434\u0440\u043e\u0432\u043e \u043f\u043e \u043d\u0435\u043c\u0443 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u0441\u044f, \u043f\u043e\u043a\u0430 \u043a\u0430\u0434\u0440\u044b \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0430\u0442\u0441\u044f, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u0430\u0434\u0440\u0430:<\/p>\n<ol>\n<li>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u0421\u043a\u0435\u0439\u043b\u0438\u043c \u0435\u0433\u043e \u0434\u043e \u043d\u0443\u0436\u043d\u044b\u0445 \u043d\u0430\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 (\u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0438\u043a\u0441\u0435\u043b\u0438 \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e, \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u044f:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u044c<\/p>\n<\/li>\n<li>\n<p>\u0421\u0442\u0430\u0432\u0438\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0435\u0433\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u0438 \u0441\u0438\u043c\u0432\u043e\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u0441\u0445\u043e\u0436\u0443\u044e \u044f\u0440\u043a\u043e\u0441\u0442\u044c (\u0431\u043e\u043b\u0435\u0435 \u044f\u0440\u043a\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b &#8212; \u0437\u043d\u0430\u0447\u0438\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439) <\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>\u0412\u044b\u0432\u043e\u0434\u0438\u043c \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u043a\u0443<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h2>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0434\u0435\u043b\u0443:<\/h2>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432.<\/p>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, ncurses \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c (\u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u0435\u0437 \u043d\u0435\u0433\u043e): <\/p>\n<pre><code class=\"cpp\">#include &lt;chrono> #include &lt;iostream> #include &lt;opencv2\/opencv.hpp> #include &lt;opencv2\/videoio.hpp> #include &lt;string> #include &lt;thread> \/\/ \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u044b chrono \u0438 thread :D?  \/\/ \u0421\u0438\u0448\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435 \u043f\u043b\u044e\u0441\u043e\u0432\u044b\u0445 #include &lt;curses.h> #include &lt;ncurses.h><\/code><\/pre>\n<p>\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0432\u0438\u0434\u0435\u043e \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 VideoCapture, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u0432\u0438\u0434\u0435\u043e:<\/p>\n<pre><code class=\"cpp\">cv::VideoCapture video_capture(\"\/path\/to\/video\")); if (!video_capture.isOpened()) {     std::cerr &lt;&lt; \"Failed to open video file.\\n\";     return -1;   } <\/code><\/pre>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b:<\/p>\n<pre><code class=\"cpp\">\/\/ \u042d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u044d\u0444\u0438\u0446\u0435\u043d\u0442  \/\/ \u043d\u0443\u0436\u043d\u044b\u0439 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0440\u043e\u043d \u0432\u0438\u0434\u0435\u043e \u043f\u0440\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043a\u0435\u0439\u043b\u0435  \/\/ \u043c\u043e\u0435\u0439 \u043a\u043e\u043d\u0441\u043e\u043b\u0438   const float correction_factor = 4.75;  \/\/ \u041e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0431\u0443\u0434\u0435\u043c 10 \u0440\u0430\u0437 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \/\/ \u0438\u043d\u0430\u0447\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0442\u0430\u0439\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0448\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u0432\u0438\u0434\u0435\u043e   const int targetfps = 10;   const int fps = video_capture.get(cv::CAP_PROP_FPS);   const int fpsdif = fps \/ targetfps;   const int frame_duration = 1000 \/ fps;  \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0432\u0438\u0434\u0435\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u0445, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d   const int frame_width = video_capture.get(cv::CAP_PROP_FRAME_WIDTH);   const int frame_height = video_capture.get(cv::CAP_PROP_FRAME_HEIGHT);   const int screen_height = 120;   const int screen_width =       screen_height * (frame_width \/ frame_height) * correction_factor;<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b, \u0441\u043e\u043e\u0442\u0432. \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u0438\u043a\u0441\u0435\u043b\u044f (\u043e\u043d\u0430 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442 0 \u0434\u043e 255):<\/p>\n<pre><code class=\"cpp\"> const char get_ASCII_from_pixel(const int pixelintensity) {   \/\/ \u0412\u044b\u0431\u043e\u0440 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u0435\u043d, \u043c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0442\u0430\u043a   std::string chars_by_brightness = \"$@B%8&amp;#*\/|(-_+;:,.  \";   \/\/ \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c   std::reverse(chars_by_brightness.begin(), chars_by_brightness.end());       return chars_by_brightness[static_cast&lt;float>(pixelintensity *                                                 chars_by_brightness.length()) \/                              256.f]; }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 \u0446\u0438\u043a\u043b\u0443:<\/p>\n<pre><code class=\"cpp\"> \/\/ \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u043a\u0430\u0434\u0440\u0430,  \/\/ \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0447\u0435\u0441\u0442\u044c \u0435\u0433\u043e \u0438\u0437 \u0444\u0440\u0435\u0439\u043c\u0442\u0430\u0439\u043c\u0430   int starttime = 0, endtime = 0, framedrawtime = 0, i = 0;  \/\/ \u041e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0446\u0438\u043a\u043b\u0435 \/\/ cv::Mat - \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 n-\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \/\/ \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043a\u0430\u0434\u0440 (\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b - \u043f\u0438\u043a\u0441\u0435\u043b\u0438)   cv::Mat original_frame, grayscaled_frame, grayscaled_resized_frame;    initscr(); \/\/ \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0432 curses \u0440\u0435\u0436\u0438\u043c   for (;;) {     \/\/ \u0437\u0430\u0441\u0435\u043a\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u044f     starttime = std::chrono::duration_cast&lt;std::chrono::milliseconds>(                     std::chrono::system_clock::now().time_since_epoch())                     .count();          \/\/ \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u0434\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u043c     i = fpsdif;     while (--i) {       video_capture.grab();     }      \/\/ \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 >> \u0443 cv::VideoCapture \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0430\u0434\u0440     video_capture >> original_frame;      \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u0432\u0438\u0434\u0435\u043e     if (original_frame.empty())       break;      \/\/ \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443     cv::cvtColor(original_frame, grayscaled_frame, cv::COLOR_BGR2GRAY);     cv::resize(grayscaled_frame, grayscaled_resized_frame,                cv::Size(screen_width, screen_height), 0, 0, cv::INTER_LINEAR);      for (int x = 0; x &lt; screen_height; ++x) {       for (int y = 0; y &lt; screen_width; ++y) {         \/\/ \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c \u043a\u0430\u0440\u0435\u0442\u043a\u0443 curses \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0442\u0443\u0434\u0430 \u0441\u0438\u043c\u0432\u043e\u043b         mvaddch(x, y,                 get_ASCII_from_pixel(grayscaled_resized_frame.at&lt;uchar>(x, y)));       }     }      \/\/ \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438     refresh();         endtime = std::chrono::duration_cast&lt;std::chrono::milliseconds>(                   std::chrono::system_clock::now().time_since_epoch())                   .count();          \/\/ \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0448\u043b\u043e \u0443\u0436\u0435     framedrawtime = endtime - starttime;      \/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u043b\u0438\u0442\u0441\u044f \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e     std::this_thread::sleep_for(         std::chrono::milliseconds(fpsdif * frame_duration - framedrawtime));   }    endwin(); \/\/ \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 curses \u0440\u0435\u0436\u0438\u043c\u0430<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0412\u0435\u0441\u044c \u043a\u043e\u0434: <\/summary>\n<div class=\"spoiler__content\">\n<p>src\/main.cpp<\/p>\n<pre><code class=\"cpp\">#include &lt;chrono> #include &lt;iostream> #include &lt;opencv2\/opencv.hpp> #include &lt;opencv2\/videoio.hpp> #include &lt;string> #include &lt;thread>  #include &lt;ncurses.h>  const std::string getpathto(const char *file) {   std::stringstream ss;   ss &lt;&lt; RESOURCES_PATH &lt;&lt; file;   return ss.str(); }  const char get_ASCII_from_pixel(const int pixelintensity) {   std::string chars_by_brightness = \"$@B%8&amp;#*\/|(-_+;:,.  \";   std::reverse(chars_by_brightness.begin(), chars_by_brightness.end());   return chars_by_brightness[static_cast&lt;float>(pixelintensity *                                                 chars_by_brightness.length()) \/                              256.f]; }  int main() {   cv::VideoCapture video_capture(getpathto(\"vid1.mp4\"));    if (!video_capture.isOpened()) {     std::cerr &lt;&lt; \"Failed to open video file.\\n\";     return -1;   }    const float correction_factor = 4.75;   const int targetfps = 10;   const int fps = video_capture.get(cv::CAP_PROP_FPS);   const int fpsdif = fps \/ targetfps;   const int frame_duration = 1000 \/ fps;   const int frame_width = video_capture.get(cv::CAP_PROP_FRAME_WIDTH);   const int frame_height = video_capture.get(cv::CAP_PROP_FRAME_HEIGHT);   const int screen_height = 120;   const int screen_width =       screen_height * (frame_width \/ frame_height) * correction_factor;    int starttime = 0, endtime = 0, framedrawtime = 0, i = 0;   cv::Mat original_frame, grayscaled_frame, grayscaled_resized_frame;    initscr();   for (;;) {     starttime = std::chrono::duration_cast&lt;std::chrono::milliseconds>(                     std::chrono::system_clock::now().time_since_epoch())                     .count();     i = fpsdif;     while (--i) {       video_capture.grab();     }      video_capture >> original_frame;     if (original_frame.empty())       break;      cv::cvtColor(original_frame, grayscaled_frame, cv::COLOR_BGR2GRAY);     cv::resize(grayscaled_frame, grayscaled_resized_frame,                cv::Size(screen_width, screen_height), 0, 0, cv::INTER_LINEAR);      for (int x = 0; x &lt; screen_height; ++x) {       for (int y = 0; y &lt; screen_width; ++y) {         mvaddch(x, y,                 get_ASCII_from_pixel(grayscaled_resized_frame.at&lt;uchar>(x, y)));       }     }      refresh();      endtime = std::chrono::duration_cast&lt;std::chrono::milliseconds>(                   std::chrono::system_clock::now().time_since_epoch())                   .count();      framedrawtime = endtime - starttime;      std::this_thread::sleep_for(         std::chrono::milliseconds(fpsdif * frame_duration - framedrawtime));   }    endwin();    return 0; } <\/code><\/pre>\n<p>CMakeLists.txt<\/p>\n<pre><code class=\"cmake\">cmake_minimum_required(VERSION 3.25) project(ASCII_video) set(OpenCV_DIR \/usr\/lib\/opencv4\/opencv2) find_package(OpenCV REQUIRED) find_package(Curses REQUIRED) # find_package(VTK REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS} ${CURSES_INCLUDE_DIR})  add_executable(MyExecutable src\/main.cpp)  target_link_libraries(MyExecutable ${OpenCV_LIBS} ${VTK_LIBRARIES} ${CURSES_LIBRARIES}) target_compile_definitions(MyExecutable PUBLIC RESOURCES_PATH=\"${CMAKE_CURRENT_SOURCE_DIR}\/resources\/\")  <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u0418\u0442\u043e\u0433:<\/h2>\n<p>\u0412\u0438\u0434\u0435\u043e:<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/655f25bb3eb8e176bff28d96\" data-style=\"\" id=\"655f25bb3eb8e176bff28d96\" width=\"\"><\/div>\n<p>\u041e\u043d\u043e \u0436\u0435, \u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438:<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/655f25c93add7830898fcbe9\" data-style=\"\" id=\"655f25c93add7830898fcbe9\" width=\"\"><\/div>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/768456\/\"> https:\/\/habr.com\/ru\/articles\/768456\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-357910","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/357910","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=357910"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/357910\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=357910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=357910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=357910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}