星星甲壳虫 2019-04-26 17:37 采纳率: 0%
浏览 581

OpenCV+vs2015的简单问题

#include
#include
using namespace cv;
using namespace dnn;
using namespace std;
String model_file = "bvlc_googlenet .caffemodel";
String model_txtfile = "bvlc_googlenet.prototxt";
String labels_file = "synset_words.txt";
vectorreadLabels();

int main(int arc, char** argv) {
Mat src = imread("D:/messi5.jpg");
namedWindow("input", CV_WINDOW_AUTOSIZE);
imshow("input", src);

//读取模型的类别(文本)
vector<String> labels = readLabels();

//读取google_net的模型和描述文件
Net net = readNetFromCaffe(model_txtfile, model_file);
if (net.empty()) {
    printf("read caffee model data failure\n");
    return -1;
}
//将图像转为google_net网络输入的对象,由描述文件可知,图像尺寸统一为224*224
Mat inputBlob = blobFromImage(src, 1.0, Size(224, 224), Scalar(104, 117, 123));

//进行前向传播,由描述文件可知,第一层用了10个卷积层,提取图像10种不同的特征
Mat prob;
for (int i = 0; i < 10; i++) {
    net.setInput(inputBlob, "data");
    prob = net.forward("prob");//最后一层的输出为“prob”
}

//输出
//printf("m = %d,n = %d", prob.rows, prob.cols);//得到的概率值为1行1000列的
Point classLoc;
double classProb;
minMaxLoc(prob, NULL, &classProb, NULL, &classLoc);
printf("current image classification: %s,probablity %f\n", labels.at(classLoc.x).c_str(), classProb);
putText(src, labels.at(classLoc.x), Point(20, 20), FONT_HERSHEY_COMPLEX, 1.0, Scalar(0, 0, 255), 2);
imshow("output", src);
waitKey(0);
return 0;

}

//读取模型的类别(文本)
vectorreadLabels() {
vectorclassNames;
ifstream fp(labels_file);//打开文件
if (!fp.is_open()) {//文件没打开
printf("could not open the file ");
exit(-1);
}
string name;
while (!fp.eof()) {//文件没读到结尾
getline(fp, name);//得到每一行,放到name中
if (name.length()) {//非空行
classNames.push_back(name.substr(name.find(' ') + 1));//
}
}
fp.close();
return classNames;
}

我在vs2015上运行过这段代码,别人可以运行成功,但是我出现这个问题(“”)could not open the file。不知道什么问题

  • 写回答

1条回答 默认 最新

  • 天地之心online 2019-04-27 14:10
    关注

    文件存在吗?路径对吗?都对就不知道了

    评论

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果