执行以下操作时:
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <highgui.h>
using namespace std;
std::vector<double> getPosVector(string path) {
const char *dir = path.c_str();
struct dirent *dp;
DIR *fd;
int count = 0;
std::vector<double> myvector;
if ((fd = opendir(dir)) == NULL) {
fprintf(stderr, "listdir: can't open %s\n", dir);
return myvector;
}
while ((dp = readdir(fd)) != NULL) {
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
continue; /* skip self and parent */
// Load image as matrix, keep directory
string currentImage = path+'/'+dp->d_name;
// Load image
cv::Mat image;
image = cv::imread(currentImage.c_str(),CV_LOAD_IMAGE_COLOR);
if(!image.data) {
cout << "Could not load image file: " << endl;
}
// Find image dimensions
int rows = image.rows;
int cols = image.cols;
double s = cv::sum(image)[0];
double mean = s/(rows*cols);
myvector.push_back(mean);
}
closedir(fd);
return myvector;
}
int main(int argc, char* argv[])
{
// Check argument
if(argc<3) {
cout << "Usage: CRForest-Detector.exe mode [config.txt] [tree_offset]" << endl;
cout << "mode: 0 - train; 1 - show; 2 - detect" << endl;
cout << "tree_offset: output number for trees" << endl;
cout << "Load default: mode - 2" << endl;
} else
std::vector<double> pos_vector = getPosVector(argv[1]);
cout << pos_vector.size() << endl;
return 0;
}
我收到此消息:
getThreshold.cpp: In function ‘int main(int, char**)’:
getThreshold.cpp:130:22: error: ‘pos_vector’ was not declared in this scope
cout << int(pos_vector.size()) << endl;
^
make: *** [getThreshold.o] Error 1
我已经远远地看了解决方案,但我不能这样做。谢谢你的帮助。
我的makefile看起来像这样(我在linux上并使用g ++):
INCLUDES = -I/usr/include/opencv
LIBS = -lcxcore -lcv -lcvaux -lhighgui -lml
LIBDIRS = -L/usr/local/lib
OPT = -O3 -Wno-deprecated
CC=g++
.PHONY: all clean
OBJS = getThreshold.o
clean:
rm -f *.o *~ getThreshold
all: getThreshold
echo all: make complete
%.o:%.cpp
$(CC) -c $(INCLUDES) $+ $(OPT) `pkg-config --libs --cflags opencv` `pkg-config --libs opencv`
getThreshold: $(OBJS)
$(CC) -o $@ $+ $(OPT) `pkg-config --libs --cflags opencv` `pkg-config --libs opencv`