|
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;
问题有点多,自己看吧
别人要调试你的这个程序
就需要先下载一个vs2015或者以上版本
然后再下载一个opencv的windows版本
然后再下载一个easyx
折腾半天才能运行这个代码
你的这个问题都过去好长时间了,别人还没有帮你
这就是原因
所以,自己学着调试程序吧,指望别人大概率是指望不上
还得靠自己
- //#include <stdio.h> 为什么要用这个?
- #include <string>
- #include <iostream>
- #include <opencv2/opencv.hpp>
- #include <graphics.h>
- #include <windows.h>
- //#include <mmsystem.h>
- //#pragma comment(lib,"winmm.lib")
- using namespace cv;
- using namespace std;
- int main() {
- //initgraph(640, 480, EW_SHOWCONSOLE); //创建窗口
- initgraph(1440, 900, EW_SHOWCONSOLE); //创建窗口
- // setbkcolor(BLACK);//设置窗口背景颜色为黑色
- // cleardevice();//刷新
- // setbkmode(TRANSPARENT);//设置背景模式,去掉文字背景
- settextstyle(12, 0, "楷体"); //设置字体
- // settextcolor(WHITE);//设置文字颜色
- /*
- int width = textwidth('@'); // 6
- int height = textheight('@'); // 12
- */
- VideoCapture mvideo("test.mp4"); //获取视频
- //const char *str = "!@#$%^&*()_+. "; //替换的字符
- const char* str = R"($@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_ +~<>i!lI;:,"^`'. )"; //替换的字符
- //int len = strlen(str); //求字符的长度
- size_t len = strlen(str); // strlen 返回的不是int,是size_t
- 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));
- */
- // 1440 / 6
- // 900 / 12
- resize(frame, show, Size(1440, 900)); //重新设置图片大小
- resize(frame, frame, Size(1440 / textwidth('@'), 900 / textheight('@')));
- cleardevice(); //清空,回到(0,0)的位置
- //for(int x = 0; x < frame.rows; x++) { //获取每一个像素点
- //for(int y = 0; y < frame.cols; y++) {
- for(int y = 0; y < frame.rows; ++y) { //获取每一个像素点
- for(int x = 0; x < frame.cols; ++x) {
- //int grayval = frame.at<uchar>(x, y); //获取单通道颜色的值
- int grayval = frame.at<uchar>(y, x); //获取单通道颜色的值
- index = int(grayval / 256.0 * len); //获取颜色的比例
- //text += str[index];
- text += str[len - index - 1];
- }
- //outtextxy(0, x * textheight(str[index]), text.data()); //逐行输出
- outtextxy(0, y * textheight(text[0]), text.data()); //逐行输出
- text.clear(); //每一行清除一次
- }
- imshow("test", show);
- //cv::waitKey(3000); // 这里为什么要指定名字空间?
- //waitKey(3000); // 一帧3秒?
- waitKey(50);
- FlushBatchDraw();
- }
- //cv::waitKey(3000);
- waitKey(3000);
- // *********************************************
- closegraph(); // 创建了窗口用完后不关闭吗?
- // *********************************************
-
- return 0;
- }
复制代码
|
最佳答案
查看完整内容
问题有点多,自己看吧
别人要调试你的这个程序
就需要先下载一个vs2015或者以上版本
然后再下载一个opencv的windows版本
然后再下载一个easyx
折腾半天才能运行这个代码
你的这个问题都过去好长时间了,别人还没有帮你
这就是原因
所以,自己学着调试程序吧,指望别人大概率是指望不上
还得靠自己
|