【发布时间】:2014-04-04 00:22:46
【问题描述】:
我正在开发图像匹配程序,它从红外摄像机捕获图像并将其存储在一个目录中。图像数据库存在于不同的目录中。我在执行时得到了意想不到的结果。我不知何故意识到这是因为我弄乱了不同的目录和一些基本的东西。对解决错误有什么帮助吗?这是代码的sn-p。
VideoCapture cap(0);
Mat frame;
Mat src, dst, tmp,img_3,img_4;
filename3 = (char *)malloc(sizeof(char));
printf("\n-------------------------------------------------\n");
printf("\nOne to Many Image matching with SURF Algorithm.\n");
printf("\n-------------------------------------------------\n");
//Get the Vein image from Webcam that needs to be compared with the database.
// The below function gets frame and saves it in /home/srikbaba/opencv/veins
veincnt = captureVein(veincnt, cap);
if(veincnt == -1)
cout << "A problem has occured" << endl;
printf("\nPlease enter the filename of saved image with the extension.\n");
scanf("%s",filename3);
//Scan the directory for images.
DIR *dir;
struct dirent *ent;
clock_t tstart1 = clock(); //start clock function, do something!!!!
if ((dir = opendir ("/home/srikbaba/images")) != NULL)
{
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL)
{
if(ent->d_type!= DT_DIR)
{
//Print the images
printf ("%s\n", ent->d_name);
//Store the Filename
img_db = ent->d_name;
//Open each file name as Mat identifier and loop the process
img_3 = imread (filename3, IMREAD_GRAYSCALE);
//Filename3 is saved in /home/srikbaba/opencv/veins --> different directory
// I feel this is the problem
img_4 = imread (img_db, IMREAD_GRAYSCALE);
if( !img_3.data)
{
std::cout<< " --(!) Invalid filename or file not found! " << std::endl;
return -1;
}
因此,我总是收到 --(!) Invalid filename or file not found 消息。有没有办法可以比较一个目录中的一个图像和另一个目录中的另一个图像?我希望我所问的不会令人困惑。请帮忙。
在 Ubuntu 12.04 LTS 上使用 Opencv - C++
【问题讨论】:
标签: c++ image opencv directory