在图像上覆盖文本的程序会产生无休止的字符串错误
Program to overlay text on an image gives endless string errors
我写了一个简短的程序来覆盖图像上的文本:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void drawMM( const cv::Mat mm, std::string mCap ){
//Input output windows
cv::namedWindow( "Example2_5-out", cv::WINDOW_AUTOSIZE );
//Input window
cv::imshow( "Example2_5-in", mm );
//The Holder of Output(Copyright 2009 Holders Series)
cv::Mat out = mm.clone();
//Smoothing
cv::putText(out, mCap, cv::Point(40,200), cv::FONT_HERSHEY_PLAIN, 2.0, 255, 2);
//Show the output image.
cv::imshow( "Example2_5-out", out);
//Wait.
cv::waitKey( 0 );
}
void inStr(int argc, char* argv[]){
if (argc == 1)
{
string st = "If your boyfriend dosn't know what this is.";
cout << st << endl;
}else{
string st = argv[1];
cout << st << endl;
}
}
int main(int argc, char *argv[]) {
string mT << inStr() << endl;
cv::Mat img = cv::imread(argv[1]);
drawMM(img, mT);
return 0;
}
但是无论我做什么,每次尝试编译它时都会收到两个错误:
- 意外的令牌:
CMG--00.cpp:39:15: error: expected initialiser before ‘<<’ token
string mT << inStr() << endl;
- 未声明的范围:
CMG--00.cpp:41:17: error: ‘mT’ was not declared in this scope
drawMM(img, mT);
谁能告诉我我做错了什么?
string mT << inStr() << endl;
这条线有几个问题。首先,您不能在此处使用operator<<
。如果要创建变量,请使用string mT = inStr();
此外,你的函数inStr
有两个参数:argc 和 argv,就像你的主函数一样。您必须将这些参数传递给函数。这会导致string mT = inStr(argc, argv);
下一个问题是您的inStr
函数:您正在使用在控制台中打印某些内容的cout
而不是返回字符串。您必须调整inStr
:将void
替换为string
并使用return st;
而不是当前cout
。
我建议阅读另一个教程,因为您似乎对该语言缺乏一些基本的了解。
相关文章:
- 是什么阻止DOMTimerCoordinator::NextID进入无休止的循环
- 关于 SIGTSTP 错误和无休止的输入
- 宽藤会话更新无休止循环
- 为什么析构函数无休止地调用自己(导致堆栈溢出)?
- 在图像上覆盖文本的程序会产生无休止的字符串错误
- OpenSSL客户端陷入无休止的读取
- 自定义删除器,用于shared_ptr<>给出"无上下文错误"
- 无休止的 do while 循环C++代码
- 无操作员错误代码
- 循环无休止地做
- 操作员无匹配==错误,C
- 卡死胡同-无休止的循环,没有解决方案
- C++:如果输入不是整数,为什么这段代码会运行一个无休止的循环
- C++无休止的循环瓶颈
- 这无休止地循环是否有明显的原因
- C++ & SDL:SDL 事件无休止地重复
- 静态分析工具,用于检测由于类型提升而导致的无休止循环
- 如何修复MacOSX上全局命名空间中缺少时间相关的无成员错误
- boost::asio系统的无休止循环:第一次连接后出现9个错误
- 使用 Visual Studio 编译创建新的客户无休止的编译错误