鱼C论坛

 找回密码
 立即注册
查看: 1346|回复: 1

[已解决]字符动画,但是视频加载不出,有没有大佬帮帮忙

[复制链接]
发表于 2022-6-26 17:05:18 | 显示全部楼层 |阅读模式
10鱼币
#include<stdio.h>
#include<easyx.h>
#include<opencv2/opencv.hpp>
#include<iostream>
#include<graphics.h>
#include<string>
#include<Windows.h>
#include<mmsystem.h>
#pragma comment(lib,"winmm.lib")

using namespace cv;
using namespace std;


int main()
{
        initgraph(640, 480,EW_SHOWCONSOLE);//创建窗口
        //setbkcolor(BLACK);//设置窗口背景颜色为黑色
        //cleardevice();//刷新
        //setbkmode(TRANSPARENT);//设置背景模式,去掉文字背景
        settextstyle(12, 0, "楷体");//设置字体
        //settextcolor(WHITE);//设置文字颜色

        VideoCapture mvideo("D:/vs2022/jj.mp4");//获取视频
       
        const char* str = "!@#$%^&*()_+. ";//替换的字符
        int len = strlen(str);//求字符的长度
        BeginBatchDraw();
        Mat frame;//视频帧;
        Mat show;
        String text;//保留转换后的字符串
        int index = 0;
        while (1)
        {
                mvideo >> frame;//导出每一帧
                if (frame.empty())break;//判断导出是否成功;
                cvtColor(frame, frame, COLOR_BGR2GRAY);//转换为灰度图
                resize(frame, show, Size(300, 150));//重新设置图片大小
                resize(frame, frame, Size(150, 50));
                cleardevice();//清空,回到(0,0)的位置
                for (int x = 0; x < frame.rows; x++)//获取每一个像素点
                {
                        for (int y = 0; y < frame.cols; y++)
                        {
                                int grayval = frame.at<uchar>(x, y);//获取单通道颜色的值
                                index = grayval / 256.0 * len;//获取颜色的比例
                                text += str[index];
                        }
                        outtextxy(0, x * textheight(str[index]), text.data());//逐行输出
                        text.clear();//每一行清除一次
                }       
                imshow("kk", show);
                cv::waitKey(3000);
                FlushBatchDraw();
        }
       
   
        cv::waitKey(3000);
        return 0;
最佳答案
2022-6-26 17:05:19
问题有点多,自己看吧
别人要调试你的这个程序
就需要先下载一个vs2015或者以上版本
然后再下载一个opencv的windows版本
然后再下载一个easyx
折腾半天才能运行这个代码
你的这个问题都过去好长时间了,别人还没有帮你
这就是原因

所以,自己学着调试程序吧,指望别人大概率是指望不上
还得靠自己

  1. //#include <stdio.h>        为什么要用这个?
  2. #include <string>
  3. #include <iostream>
  4. #include <opencv2/opencv.hpp>
  5. #include <graphics.h>
  6. #include <windows.h>

  7. //#include <mmsystem.h>
  8. //#pragma comment(lib,"winmm.lib")

  9. using namespace cv;
  10. using namespace std;

  11. int main() {
  12.     //initgraph(640, 480, EW_SHOWCONSOLE); //创建窗口
  13.     initgraph(1440, 900, EW_SHOWCONSOLE); //创建窗口
  14.     // setbkcolor(BLACK);//设置窗口背景颜色为黑色
  15.     // cleardevice();//刷新
  16.     // setbkmode(TRANSPARENT);//设置背景模式,去掉文字背景
  17.     settextstyle(12, 0, "楷体"); //设置字体
  18.     // settextcolor(WHITE);//设置文字颜色

  19.     /*
  20.     int width = textwidth('@');         // 6
  21.     int height = textheight('@');       // 12
  22.     */


  23.     VideoCapture mvideo("test.mp4"); //获取视频

  24.     //const char *str = "!@#$%^&*()_+. "; //替换的字符
  25.     const char* str = R"($@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_ +~<>i!lI;:,"^`'. )"; //替换的字符
  26.     //int len = strlen(str);              //求字符的长度
  27.     size_t len = strlen(str);             // strlen 返回的不是int,是size_t
  28.     BeginBatchDraw();
  29.     Mat frame; //视频帧
  30.     Mat show;
  31.     String text; //保留转换后的字符串
  32.     int index = 0;
  33.     while(1) {
  34.         mvideo >> frame; //导出每一帧
  35.         if(frame.empty()) break;                //判断导出是否成功;
  36.         cvtColor(frame, frame, COLOR_BGR2GRAY); //转换为灰度图
  37.         /*
  38.         resize(frame, show, Size(300, 150));    //重新设置图片大小
  39.         resize(frame, frame, Size(150, 50));
  40.         */

  41.         // 1440 / 6
  42.         // 900 / 12
  43.         resize(frame, show, Size(1440, 900));    //重新设置图片大小
  44.         resize(frame, frame, Size(1440 / textwidth('@'), 900 / textheight('@')));
  45.         cleardevice(); //清空,回到(0,0)的位置
  46.         //for(int x = 0; x < frame.rows; x++) { //获取每一个像素点
  47.             //for(int y = 0; y < frame.cols; y++) {
  48.         for(int y = 0; y < frame.rows; ++y) { //获取每一个像素点
  49.             for(int x = 0; x < frame.cols; ++x) {
  50.                 //int grayval = frame.at<uchar>(x, y); //获取单通道颜色的值
  51.                 int grayval = frame.at<uchar>(y, x); //获取单通道颜色的值
  52.                 index = int(grayval / 256.0 * len);       //获取颜色的比例
  53.                 //text += str[index];
  54.                 text += str[len - index - 1];
  55.             }
  56.             //outtextxy(0, x * textheight(str[index]), text.data()); //逐行输出
  57.             outtextxy(0, y * textheight(text[0]), text.data()); //逐行输出
  58.             text.clear(); //每一行清除一次
  59.         }
  60.         imshow("test", show);
  61.         //cv::waitKey(3000);      // 这里为什么要指定名字空间?
  62.         //waitKey(3000);       // 一帧3秒?
  63.         waitKey(50);
  64.         FlushBatchDraw();
  65.     }
  66.     //cv::waitKey(3000);
  67.     waitKey(3000);


  68.     // *********************************************
  69.     closegraph();       // 创建了窗口用完后不关闭吗?
  70.     // *********************************************
  71.    
  72.     return 0;
  73. }
复制代码

最佳答案

查看完整内容

问题有点多,自己看吧 别人要调试你的这个程序 就需要先下载一个vs2015或者以上版本 然后再下载一个opencv的windows版本 然后再下载一个easyx 折腾半天才能运行这个代码 你的这个问题都过去好长时间了,别人还没有帮你 这就是原因 所以,自己学着调试程序吧,指望别人大概率是指望不上 还得靠自己
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-6-26 17:05:19 | 显示全部楼层    本楼为最佳答案   
问题有点多,自己看吧
别人要调试你的这个程序
就需要先下载一个vs2015或者以上版本
然后再下载一个opencv的windows版本
然后再下载一个easyx
折腾半天才能运行这个代码
你的这个问题都过去好长时间了,别人还没有帮你
这就是原因

所以,自己学着调试程序吧,指望别人大概率是指望不上
还得靠自己

  1. //#include <stdio.h>        为什么要用这个?
  2. #include <string>
  3. #include <iostream>
  4. #include <opencv2/opencv.hpp>
  5. #include <graphics.h>
  6. #include <windows.h>

  7. //#include <mmsystem.h>
  8. //#pragma comment(lib,"winmm.lib")

  9. using namespace cv;
  10. using namespace std;

  11. int main() {
  12.     //initgraph(640, 480, EW_SHOWCONSOLE); //创建窗口
  13.     initgraph(1440, 900, EW_SHOWCONSOLE); //创建窗口
  14.     // setbkcolor(BLACK);//设置窗口背景颜色为黑色
  15.     // cleardevice();//刷新
  16.     // setbkmode(TRANSPARENT);//设置背景模式,去掉文字背景
  17.     settextstyle(12, 0, "楷体"); //设置字体
  18.     // settextcolor(WHITE);//设置文字颜色

  19.     /*
  20.     int width = textwidth('@');         // 6
  21.     int height = textheight('@');       // 12
  22.     */


  23.     VideoCapture mvideo("test.mp4"); //获取视频

  24.     //const char *str = "!@#$%^&*()_+. "; //替换的字符
  25.     const char* str = R"($@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_ +~<>i!lI;:,"^`'. )"; //替换的字符
  26.     //int len = strlen(str);              //求字符的长度
  27.     size_t len = strlen(str);             // strlen 返回的不是int,是size_t
  28.     BeginBatchDraw();
  29.     Mat frame; //视频帧
  30.     Mat show;
  31.     String text; //保留转换后的字符串
  32.     int index = 0;
  33.     while(1) {
  34.         mvideo >> frame; //导出每一帧
  35.         if(frame.empty()) break;                //判断导出是否成功;
  36.         cvtColor(frame, frame, COLOR_BGR2GRAY); //转换为灰度图
  37.         /*
  38.         resize(frame, show, Size(300, 150));    //重新设置图片大小
  39.         resize(frame, frame, Size(150, 50));
  40.         */

  41.         // 1440 / 6
  42.         // 900 / 12
  43.         resize(frame, show, Size(1440, 900));    //重新设置图片大小
  44.         resize(frame, frame, Size(1440 / textwidth('@'), 900 / textheight('@')));
  45.         cleardevice(); //清空,回到(0,0)的位置
  46.         //for(int x = 0; x < frame.rows; x++) { //获取每一个像素点
  47.             //for(int y = 0; y < frame.cols; y++) {
  48.         for(int y = 0; y < frame.rows; ++y) { //获取每一个像素点
  49.             for(int x = 0; x < frame.cols; ++x) {
  50.                 //int grayval = frame.at<uchar>(x, y); //获取单通道颜色的值
  51.                 int grayval = frame.at<uchar>(y, x); //获取单通道颜色的值
  52.                 index = int(grayval / 256.0 * len);       //获取颜色的比例
  53.                 //text += str[index];
  54.                 text += str[len - index - 1];
  55.             }
  56.             //outtextxy(0, x * textheight(str[index]), text.data()); //逐行输出
  57.             outtextxy(0, y * textheight(text[0]), text.data()); //逐行输出
  58.             text.clear(); //每一行清除一次
  59.         }
  60.         imshow("test", show);
  61.         //cv::waitKey(3000);      // 这里为什么要指定名字空间?
  62.         //waitKey(3000);       // 一帧3秒?
  63.         waitKey(50);
  64.         FlushBatchDraw();
  65.     }
  66.     //cv::waitKey(3000);
  67.     waitKey(3000);


  68.     // *********************************************
  69.     closegraph();       // 创建了窗口用完后不关闭吗?
  70.     // *********************************************
  71.    
  72.     return 0;
  73. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 08:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表