赞
踩
- int main()
- {
- initgraph(960, 640);
- VideoCapture mvideo("./MMD.mp4");
- mciSendString("open ./干坤坤.mp3 alias bgm", 0, 0, 0);
- const char* str = "@#$%&eb!*,';+^~. ";
- int len = strlen(str);
- BeginBatchDraw();
- Mat frame; //视频帧
- while (1)
- {
- mvideo >> frame;
- if (frame.empty())//如果读完就退出
- break;
- //把BGR颜色空间转为GRAY(转为灰度图)
- cvtColor(frame, frame, COLOR_BGR2GRAY);
- //调整图片大小
- resize(frame, frame, Size(150, 50));
- String text;//保存转换后的字符串
- cleardevice();
- int index = 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];
- }
- settextstyle(12, 0, "楷体");
- outtextxy(0, x * textheight(str[index]), text.data());//逐行输出
- text.clear();//每一行清除一次
- }
-
- imshow(" ", frame);
-
- int key = cv::waitKey(10);
- if (key == 32)//按空格退出
- break;
- mciSendString("play bgm", 0, 0, 0);
- FlushBatchDraw();
- }
-
- cv::waitKey(0);
- return 0;
- }
素材源码图形库opencv及大量学习资料都在这哦https://jq.qq.com/?_wv=1027&k=M4aUitMr
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。