是否有任何功能可以通过按不同的按钮来更改操作
Is there any function for changing the operation by pressing different buttons
我想在屏幕中间显示一个十字,并按键盘上的一些键更改它的大小。
例如如果我按 b ,十字架应该变大。如果我按 s,十字架应该变小。如果我按 m,十字架应该变成中等。
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
VideoCapture cap(0);
while(true)
{
Mat frame;
// Capture frame-by-frame
cap >> frame;
// If the frame is empty, break immediately
if (frame.empty())
break;
// for converting the frame to grayscale
Mat gray;
cvtColor( frame, gray , COLOR_BGR2GRAY);
line( frame, Point( 300, 240 ), Point( 340,240), Scalar( 0, 0, 255 ), 2, 4 );
line( frame, Point( 320, 260), Point( 320, 220), Scalar( 0, 0, 255 ), 2, 4);
imshow(" figure ",frame);
char c=(char)waitKey(25);
if(c==27)
break;
}
cap.release();
destroyAllWindows();
return 0;
}
请帮我解决这个问题
我的建议是引入"scale"变量,该变量将通过按键修改以计算两条线的起点和终点。假设这些点被定义为 [start point] = [middle point] - [scale] * [scale factor]
和 [end point] = [middle point] + [scale] * [scale factor]
.所以它看起来像:
VideoCapture cap(0);
int size = 2;
bool drawCross = 1;
while(true)
{
Mat frame;
// Capture frame-by-frame
cap >> frame;
// If the frame is empty, break immediately
if (frame.empty())
break;
// for converting the frame to grayscale
Mat gray;
cvtColor( frame, gray , COLOR_BGR2GRAY);
if (drawCross) {
line( frame, Point( 320 - 10*size, 240 ), Point( 320 + 10*size,240), Scalar( 0, 0, 255 ), 2, 4 );
line( frame, Point( 320, 240 - 10*size), Point( 320, 240 + 10*size), Scalar( 0, 0, 255 ), 2, 4);
}
imshow(" figure ",frame);
char c=(char)waitKey(25);
if(c==27)
break;
else if (c==[whatever this "small" key is])
size = 1;
else if (c==[whatever this "medium" key is])
size = 2;
else if (c==[whatever this "large" key is])
size = 4;
else if (c==[whatever this "do not draw cross" key is])
drawCross = !drawCross;
}
==编辑==解决方案现已修复,可与下面评论中给出的新"要求"一起使用。这是我对这个问题的最后一次输入,因为SO不是"你能为我写吗?"类型的社区。您在评论中描述的问题需要我长达两分钟的谷歌搜索。在继续之前,您需要阅读编程基础知识,例如条件分支之类的。而且我不知道这段代码是否 100% 有效,因为我目前不想安装C++编译器。
相关文章:
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 重载操作程序时出错>>用于类中的字符串 memebr
- 问:如何使用C++中的按钮从窗口打开窗口
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- 对字符串进行位操作
- QML按钮点击功能执行顺序
- 当用户超过按钮点击限制时报告
- 我可以在 C++ 中的函数体之外进行操作吗?
- MPI突然停止了对多个核心的操作
- 如何在信号处理程序和普通函数中对全局变量进行互斥读写操作
- 函数计算用户按下按钮的频率
- 按下Arduino按钮后,如何在C#应用程序上执行操作
- 调用函数来创建 WinAPI 按钮不会执行任何操作
- 是否有任何功能可以通过按不同的按钮来更改操作
- QListWidgetItem 当按钮单击时执行操作
- 操作菜单按钮选择bb10
- C++Builder VCL按钮阵列,每个按钮都通过其独立的点击操作动态生成
- 如何将QMessageBox按钮绑定到操作
- 按钮不执行操作
- C++ WINAPI 按钮剪贴板 - 复制操作