Opencv 3.0 features2d.hpp error : unknown AlgorithmInfo - c++

I'm developing a project using opencv3.0 with extra module found in opencv_contrib github. Im using Xcode 7.0, Yosemite 10.10.
I have done the setting in Xcode
Header Search path :
/Users/kimloonghew/Documents/opencv/opencv-3.0.0/build/include /usr/local/Cellar/libiomp/20150401/include/libiomp/omp.h /usr/local/include
Library Search path :
/Users/kimloonghew/Documents/opencv/opencv-3.0.0/build/lib /usr/local/lib
Other Linker Flag : -lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab -lopencv_nonfree -lopencv_ml -lopencv_xfeatures2d
Here the code below:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <dirent.h>
#include <string>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/ml/ml.hpp>
using namespace std;
using namespace cv;
int main(int argc, const char * argv[]) {
int minHessin = 400;
string dir = "/Users/DYKLhew/Documents/Food_proj/MIT/foodcamimages/TRAIN", filepath;
DIR *dp;
struct dirent *dirp;
struct stat filestat;
dp = opendir(dir.c_str());
SurfFeatureDetector detector(minHessin);
//Ptr<xfeatures2d::SURF> detector = xfeatures2d::SURF::create(minHessin);
vector<KeyPoint> keypoints, keypoints_scene;
Mat descriptors_object, descriptor_scene;
Mat img;
cout << "------- build vocabulary ---------\n";
cout << "extract descriptors.."<<endl;
int count = 0;
while (count++ < 15 && (dirp = readdir(dp))) {
filepath = dir + "/" + dirp->d_name;
if(stat( filepath.c_str(), &filestat )) continue;
if(S_ISDIR(filestat.st_mode)) continue;
img = imread(filepath);
detector.detect(img, keypoints);
cout << ".";
}
cout << endl;
closedir(dp);
cout << "Total descriptors : " << count << endl;
//BOWKMeansTrainer bowtrainer(150);
return 0;
}
When I run the file, it BUILD fail with the errors detected in featuares2d.hpp files. Errors as below
1) Unknown type name 'AlgorigthmInfo'; did you mean 'Algorigthm'?
2) No template named 'vector'; did you mean 'std::vector?'
Anything i did wrong when setup or installing opencv? or any linkpath i have to define?
Appreciated, for your advice. Thanks

Issues Solved:
Xcode compiler is smart and it able to predict solutions it match to your current machine configuration. If you just follow the suggestion given from the Xcode compiler, the issues was solve.
System not recognise AlgorigthmInfo, you may change to Algorigthm as well as vector to std::vector.
Now is completely working well openCV in my machine.
Hope, this will help some others if facing same issues.

Related

Objects not found in OpenCV4

This is my dir tree (root dir is untitled)
This is the content of CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(untitled)
set(CMAKE_CXX_STANDARD 11)
find_package (OpenCV 4.5.2 REQUIRED)
include_directories ("/usr/local/include/opencv4/")
add_executable(untitled main.cpp)
This is my code in main.cpp:
#include <iostream>
#include <string>
#include <sstream>
#include <opencv4/opencv2/core.hpp>
#include <opencv4/opencv2/highgui.hpp>
using namespace cv;
using namespace std;
int main(int argc, const char** argv) {
Mat color = imread("./lenna.png");
Mat gray = imread("./lenna.png", 0);
imwrite("./lennaGray.png", gray);
int myRow = color.cols - 1;
int myCol = color.rows - 1;
Vec3b pixel = color.at<Vec3b>(myRow, myCol);
cout << "Pixel value (B, G, R): (" << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << ")" << endl;
imshow("Lenna BGR", color);
imshow("Lenna Gray", gray);
waitKey(0);
return 0;
}
This is the entire error when I ran make command:
But if I ran my code in terminal by this command:
g++ main.cpp -o main -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -I/usr/local/include/opencv4 && ./main
then it worked.
I don't know what happened, I just learned OpenCV and I am using Ubuntu 20.04 and OpenCV-4.5.2.

OpenCV C++ cannot open video unless program is run as root

I'm trying to open a video file in Opencv C++, but it doesn't work in a weird way.
I'm on Fedora, and opencv is installed through dnf's opencv-devel package.
Here is the test code I'm using :
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/videoio/videoio.hpp>
int main(int argc, char *argv[])
{
std::string imagePath = "/home/me/picture.png";
cv::Mat image = cv::imread(imagePath);
std::cout << image << std::endl;
std::string videoPath = "/home/me/video.mp4";
cv::VideoCapture cap{ videoPath };
if(!cap.isOpened())
{
std::cout << "Error while opening video" << std::endl;
return -1;
}
cv::Mat startFrame;
cap >> startFrame;
std::cout << startFrame;
cap.release();
return 0;
}
Then, I Compile it with the libraries:
g++ -c -Wall -Wno-unknown-pragmas -I/usr/include/opencv4/ -o dist/obj/main.o src/main.cpp
g++ -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_videoio dist/obj/main.o -o dist/bin/main
And when I run it, the image is read fine, but the video shows an error.
However, when I run it as sudo, the video reads just fine. I searched around a lot and couldn't find someone with a similar problem, so I'm posting this here.
Also, the python version works fine, so it shouldn'ttm be a codec problem.

Run simple C++ OpenCV on Mac Terminal

I'm a complete beginner with cpp and opencv. I would like to compile and run this simple Program that lets me display an image. This works if I run the code inside XCode but if I try it using clang in the console it throws me a
linker command failed with exit code 1 (use -v to see invocation)
I had add these "linker flags" in Xcode to get opencv to run so I assume I need to somehow install them globally too. HHow would I achieve this?
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
if (argc != 2) {
cout << "Bitte zu ladendes Bild als Parameter angeben." << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
if (!image.data) {
cout << "Bild " << argv[1] << " wurde nicht gefunden." << std::endl ;
return -1;
}
namedWindow("OpenCV Window", WINDOW_AUTOSIZE);
imshow("OpenCV Window", image);
cout << "Image width: " << image.cols << ", image height: " <<
image.rows << endl;
waitKey(0);
return 0;
}
These are the Linker Flags inside Xcode:
-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videoio -lopencv_videostab

OpenCV example compilation results in core dump

I am compiling an example for OpenCV with the following code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
The compilation code is:
g++ -I/usr/local/include/opencv2 `pkg-config --cflags --libs opencv` -L /usr/local/share/OpenCV/3rdparty/lib/ opencv.cpp -o opencv -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_features2d -lopencv_imgcodecs
If I omit one of the libraries I add additionally, I get linking errors. When trying to run the program, I get an"Invalid machine code" error. How can that be solved?

crash without error message opencv under Qt

I have a problem under Qt, Actually I want to use opencv under it (ubuntu) and there is a crash.
If I compile under the terminal :
g++ pkg-config --cflags opencv example.cc -o output_file pkg-config --libs opencv
All is all right but under QT there is a crashed problem and I just read this message error :
Starting /home/quentin/build-test_opencv-Desktop_Qt_5_2_1_GCC_64bit-Release/test_opencv...
The program has unexpectedly finished.
/home/quentin/build-test_opencv-Desktop_Qt_5_2_1_GCC_64bit-Release/test_opencv crashed
This is my .pro :
QT += core
QT -= gui
TARGET = test_opencv
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
CONFIG += link_pkgconfig
PKGCONFIG += opencv
SOURCES += main.cpp
INCLUDEPATH += -I /usr/local/include/opencv
LIBS += `pkg-config opencv --libs`
and this is my main.cpp :
#include <QCoreApplication>
#include <iostream>
#include "cv.h"
#include "highgui.h"
using namespace std;
int main(int argc, char *argv[])
{
IplImage* img = cvLoadImage( "lena.png" );
cout << "Image WIDTH = " << img->width << endl;
cout << "Image HEIGHT = " << img->height << endl;
cvReleaseImage( &img );
return 0;
}
Most likely cvLoadImage fails and returns nullptr. You never bother checking for that.
What version of openCV do you use? What berak means is that IplImage is not used in the newer versions of openCV. Use Mat instead of IplImage. Try this code and tell me what happens:
#include <QCoreApplication>
#include <iostream>
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include "opencv2/highgui/highgui.hpp"
int main(int argc, char *argv[])
{
Mat* img = new cv::Mat(cv::imread("lena.png",CV_LOAD_IMAGE_COLOR));
if(img == NULL){
perror("Could not load image");
}
std::cout << "Image WIDTH = " << img->cols << std::endl;
std::cout << "Image HEIGHT = " << img->rows << std::endl;
img->release();
return 0;
}
This will work in opencv 2.4.X. Also make sure your image is in the same folder as your program. Please tell me of any error.