- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有这个问题,
当我使用 vs2010(调试)(打开 cv 2.4.0)运行时,facerec_demo.cpp 给我程序这个错误
OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in unknown function, file ......\src\opencv\modul es\core>\src\matrix.cpp, line 801
这个错误将我带到 facerec.cpp 中的这一行
(Fisherfaces::train(InputArray src, InputArray _lbls)
Mat data = asRowMatrix(src, CV_64FC1); <-- this gets a exeption, not handled.
我在 pgm img 数据库中使用,这是我的原始 *facerec_demo.cpp* 文件
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
using namespace cv;
using namespace std;
vector<string> split_at_commas(const string& row)
{
vector<string> res;
istringstream buf(row);
string s;
while (getline(buf, s, ';'))
res.push_back(s);
return res;
}
Mat toGrayscale(InputArray _src) {
Mat src = _src.getMat();
// only allow one channel
if(src.channels() != 1)
CV_Error(CV_StsBadArg, "Only Matrices with one channel are supported");
// create and return normalized image
Mat dst;
cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC1);
return dst;
}
void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator = ';') {
//std::ifstream file(filename.c_str(), ifstream::in);
std::ifstream file(_T("D:\\Users\\PC ACER\\Documents\\mycsv4.csv"));
if (!file)
throw std::exception();
string line="", path="", classlabel="";
while (getline(file, line)) {
//vector<string> values = split_at_commas(line);
stringstream liness(line);
getline(liness, path, ';');
getline(liness, classlabel);
images.push_back(imread(path, 0));
labels.push_back(atoi(classlabel.c_str()));
}
}
int main(int argc, const char *argv[]) {
// check for command line arguments
if (argc != 2) {
cout << "usage: " << argv[0] << " <csv.ext>" << endl;
exit(1);
}
// path to your CSV
string fn_csv = string(argv[1]);
// images and corresponding labels
vector<Mat> images;
vector<int> labels;
// read in the data
try {
read_csv(fn_csv, images, labels);
} catch (exception&) {
cerr << "Error opening file \"" << fn_csv << "\"." << endl;
exit(1);
}
// get width and height
//int width = images[0].cols;
int height = images[0].rows;
// get test instances
Mat testSample = images[images.size() - 1];
int testLabel = labels[labels.size() - 1];
// ... and delete last element
images.pop_back();
labels.pop_back();
// build the Fisherfaces model
Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
model->train(images, labels);
// test model
int predicted = model->predict(testSample);
cout << "predicted class = " << predicted << endl;
cout << "actual class = " << testLabel << endl;
// get the eigenvectors
Mat W = model->eigenvectors();
// show first 10 fisherfaces
for (int i = 0; i < min(10, W.cols); i++) {
// get eigenvector #i
Mat ev = W.col(i).clone();
// reshape to original size AND normalize between [0...255]
Mat grayscale = toGrayscale(ev.reshape(1, height));
// show image (with Jet colormap)
Mat cgrayscale;
applyColorMap(grayscale, cgrayscale, COLORMAP_JET);
imshow(format("%d", i), cgrayscale);
}
waitKey(0);
return 0;
}
最佳答案
我看到您正在使用 OpenCV 2.4.0。作为开发人员,我承认困惑是我的错:当时我没有彻底检查传递给训练方法的输入数据,所以传递错误对齐数据的人会得到像你这样的错误消息。您看到的错误很可能会发生,因为您的训练图像大小不等。这对于 Eigenfaces 和 Fisherfaces 算法是必需的(对于 Local Binary Patterns Histograms 不是)。 OpenCV 2.4.0 只是尝试将数据重新整形为矩阵,然后出现您看到的错误消息; OpenCV 2.4.2 改为检查(在训练之前)输入数据是否正确对齐并抛出一个有意义的异常......带有非常明确的消息。
这篇文章假设它也可能是由于链接了 OpenCV 库:
如果它没有链接库,则可能是由于图像大小。调整训练图像的大小,可以使用 OpenCV 轻松完成 cv::resize :
但您可能应该考虑切换到 OpenCV 2.4.2,其中添加了所有这些内容:
此版本还附带了详尽的文档:
但是,如果您不能更改为 OpenCV 2.4.2,并且需要继续使用 OpenCV 2.4.0,那么您也可以使用 libfacerec:
这是合并到 OpenCV 中的项目。我确保它可以与 OpenCV 2.4.0 一起使用,并且它将为您提供与 OpenCV 2.4.2 版本完全相同的界面。因此,一旦您想更新到 OpenCV 2.4.2,您只需切换包含项即可。
关于c++ - 打开简历 fisherfaces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11606737/
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我开始在我的图像处理程序中使用 OpenCV。当我使用 cv::Mat 并在内存方法中分配时: cv::Mat coords(100, 5, CV_32FC1); 如果我不再需要,是否需要执行 coo
hibernate :插入数据文件(file_content、file_name、doc_title、resume_text、title、title_id、file_type)值(?、?、?、?、?、
我正在尝试为求职申请制作一份简历,现在我已经使用 CSS 创建了一个背景和一个小菜单。现在我的问题: 有没有办法不使用 ,,创建一个区域,我可以在不丢失菜单的情况下将我的链接定位到该区域。 当我学习
我正在运行这段代码: #include #include #include using namespace cv; using namespace std; int main( int argc
python 3.5 和 windows 10 我使用这个命令安装了 open cv : pip install opencv_python-3.1.0-cp35-cp35m-win_amd64.wh
我在 Linux Mint 上安装了 opencv 使用: sudo apt-get install python-opencv 当我尝试使用以下方法导入 opencv 模块时: from openc
我是否可以搜索特定日期提交的 CVS 文件列表? 我目前使用 opensuse 和 cvs 命令行,还使用 Eclipse IDE 处理我的 Java 内容。 最佳答案 您可以使用 Eclipse
当我执行 rtag 时,进程相当慢,消息 cvs rtag: [07:34:59] waiting for cvsuser's lock in ...;是什么导致了这个以及如何解决这个问题?提前致谢。
我使用 OpenCV 和 MATLAB 校准了带有棋盘格图案的相机。我在 OpenCV 和 MATLAB 中分别得到了 .489 和 .187 的平均重投影误差。从它的外观来看,MATLAB 更精确。
将一个 html 页面集成到另一个 html 页面的最简单方法是什么?我在我的个人网站上工作,我有一个正在编辑的模板。现在我找到了一个可以使用的免费简历 html 代码,但是当我尝试将它添加到我的网站
在 VS2015 中构建一个简单的 OpenCV 应用程序时出现错误 'cv': a namespace with this name does not exist while building 虽然
我是一名优秀的程序员,十分优秀!