Eclipse 给出"weird"关于 opencv 的错误

Eclipse giving "weird" error concerning opencv

本文关键字:错误 opencv weird 给出 Eclipse 关于      更新时间:2023-10-16

我正在运行ubuntu 12.04。我有一个 c++ 项目,我在 Eclipse(luna 之前的版本(中编写和编译得很好。我的系统遇到了一些问题,不得不重新安装操作系统。现在我正在使用Eclipse luna,该项目在使用某些openCV功能时给出了一个奇怪的错误。

当我使用cv::namedWindow()cv::imshow()时,我遇到的错误。错误是:

以下是 eclipse 控制台输出:

00:21:45 **** Incremental Build of configuration Debug for project MySOM ****
make all 
Building target: MySOM
Invoking: Cross G++ Linker
g++ -L/usr/local/lib -o "MySOM"  ./src/LoadFile.o ./src/Model.o ./src/Node.o ./src/SOM.o ./src/main.o   -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab
Finished building target: MySOM

00:21:45 Build Finished (took 210ms)

它看起来在上面找到,但随后...

以下是日食中的"问题"选项卡:

Description Resource    Path    Location    Type
Invalid arguments '
Candidates are:
bool imwrite(const ? &, const cv::_InputArray &, const ? &)
'   SOM.cpp /MySOM/src  line 211    Semantic Error
Invalid arguments '
Candidates are:
cv::Mat imread(const ? &, int)
'   LoadFile.cpp    /MySOM/src  line 10 Semantic Error
Invalid arguments '
Candidates are:
void imshow(const ? &, const cv::_InputArray &)
'   main.cpp    /MySOM/src  line 22 Semantic Error
Invalid arguments '
Candidates are:
void namedWindow(const ? &, int)
'   main.cpp    /MySOM/src  line 21 Semantic Error

主.cpp

#include "Node.h"
#include <iostream>
#include "SOM.h"
#include <string>
#include "opencv2/core/core.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>//FOR TESTING

void MyPause(std::string msg){
    if(msg != ""){
        std::cout << "[+] " << msg << std::endl;
    }
    std::cout << "Press enter to continue" << std::endl;
    std::cin.get();
}
void DisplayMat(cv::Mat img){
    static int number = 0;
    cv::namedWindow( "Input" + number, cv::WINDOW_AUTOSIZE );// ERROR HERE
    cv::imshow( "Input" + number, img );//ERROR HERE
    cv::waitKey(0);
    number++;
    return;
}

std::string filename = "/home/myUserName/Code/projectFiles/testMedia/myYellow.jpg";

int main(){
    //cv::Mat inputImg = LoadFile(filename);
    SOM som(filename);
    MyPause("After SOM initialization");
    DisplayMat(som.inputImg);
    MyPause("END OF MAIN");
    return 0;
}

我想知道这是否会发生,因为与我在原始系统上编译它的方式相比,我现在编译 opencv 的方式。

当我升级日食时,这种情况一直发生在我身上。它有Member declaration not foundinvalid overload of endlInvalid arguments ...的所有奇怪错误,现在我发现这是工作区中的信息,旧项目对于新的CDT codan来说不是最新的。解决这个问题其实很容易:Project->C/C++ index->Rebuild。完成后,所有奇怪的错误都会消失。

在执行此操作之前,我已经尝试了 3 次刷新、清洁和重建,但似乎在发布后我尝试了第四次只是为了确保它已经起作用了。

此表达式无效:"Input" + number .不能只将字符串文字与数字连接起来。好吧,你可以,但结果不会是你所期望的。

幸运的是,您正在C++编程,这意味着您可以使用std::stringstd::to_string(如果您有兼容C++11的编译器(:std::string("Input") + std::to_string(number)

如果您没有 C++11,因此没有 std::to_string ,那么您可以使用例如 Boost 词法转换库,或std::istringstream来格式化字符串,或其他格式化函数/库。