I'm trying to use the inpaint function in opencv, but I'm getting this error
loadimg.cpp: In function 'int main(int, char**)':
loadimg.cpp:19:28: error: 'INPAINT_TELEA' is not a member of 'cv'
loadimg.cpp:19:45: error: 'inpaint' was not declared in this scope
From typing this:
C:\Users\Francesco\Desktop\prova>g++ -I"C:\opencv\build\include"
-L"C:\opencv\build\x86\mingw\lib" loadimg.cpp -lopencv_core245 -lopencv_highgui245
-lopencv_img proc245 -o loadimg
This is my code:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv/cv.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat src = cv::imread("prova.jpg");
Mat mask;
cvtColor(src, mask, CV_RGB2GRAY);
threshold(mask, mask, 220, 255, CV_THRESH_BINARY);
Mat dst;
inpaint(src, mask, dst, 1, cv::INPAINT_TELEA);
imshow("image", dst);
waitKey(0);
return 0;
}
Can anyone help me? Thank you very much.
cv::inpaint() is declared in the photo module. You need to #include <opencv2/photo/photo.hpp> . Alternatively, you could #include <opencv2/opencv.hpp>, which includes all of OpenCV's functionality.
try:
inpaint(src, mask, dst, 1, INPAINT_TELEA);
Also, include :opencv2/photo/photo.hpp
Related
I try to use opencv to calculate the HoG descriptor, but an error call to "Mat" is ambiguous was raised.
I saw the answer under Error: Mat is ambiguous when using OpenCV
and I don't know whether my includes are right.
and my includes for opencv are:
#include <opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv/cv.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <opencv2/ml/ml.hpp>
#include <string>
using namespace std;
using namespace cv;
using namespace cv::ml;
here's the code:
for (int j = 0; j < original[i]; j++) {
cv::Mat train_original;
train_original = cv::imread(original_path + std::to_string(j) + ".jpg", 1);
cv::resize(train_original, train_resize_image, cv::Size(128, 128), 0, 0, CV_INTER_LINEAR);
// 计算HOG descriptor
cv::HOGDescriptor hog(cv::Size(128, 128), cv::Size(64, 64), cv::Size(16, 16), cv::Size(8, 8), 9);
hog.compute(train_resize_image,train_descriptor);
cv::Mat descriptor_mat(cv::Mat(train_descriptor).t());
train_descriptors.push_back(descriptor_mat);
}
where train_descriptor is in type of std::vector<float>
The error was raised in line
cv::Mat descriptor_mat(cv::Mat(train_descriptor).t());
Any help will be appreciated! thanks!
You should change the following line:
cv::Mat descriptor_mat(cv::Mat(train_descriptor).t());
with
cv::Mat descriptor_mat = cv::Mat(train_descriptor).t();
since Mat operator = can handle MatExpr object, while Mat constructor can not(check OpenCV documentation). But be careful with this method since it does not copy the data and shares it(like a pointer). Basically, if you want to copy the data you can do the following:
cv::Mat descriptor_mat;
cv::transpose(cv::Mat(train_descriptor),descriptor_mat);
I'm trying to create Bag-Of-Words so I can train the SVM later. I'm new with OpenCV so I used a code that I found on the Internet. The problem is that I have the following error:
OpenCV Error: Assertion failed (!_descriptors.empty()) in add, file /build/buildd/opencv-2.4.8+dfsg1/modules/features2d/src/bagofwords.cpp, line 57
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.4.8+dfsg1/modules/features2d/src/bagofwords.cpp:57: error: (-215) !_descriptors.empty() in function add
Aborted (core dumped)
And here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <iostream>
#include <string>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Ptr<FeatureDetector> features = FeatureDetector::create("FAST");
Ptr<DescriptorExtractor> descriptors = DescriptorExtractor::create("FAST");
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
//defining terms for bowkmeans trainer
TermCriteria tc(TermCriteria::MAX_ITER + TermCriteria::EPS, 10, 0.001);
int dictionarySize = 1000;
int retries = 1;
int flags = KMEANS_PP_CENTERS;
BOWKMeansTrainer bow_trainer(dictionarySize, tc, retries, flags);
BOWImgDescriptorExtractor bowDE(descriptors, matcher);
//training data now
Mat mat_features1, mat_features2;
Mat img = imread("../positive_images/2014-12-07 19-55-07 804ea51d (1).JPG", 0);
Mat img2 = imread("../positive_images/Pictures23.bmp_0000_0342_0104_0564_0543.png", 0);
vector<KeyPoint> keypoints, keypoints2;
features->detect(img, keypoints);
features->detect(img2,keypoints2);
descriptors->compute(img, keypoints, mat_features1);
descriptors->compute(img2, keypoints2, mat_features2);
bow_trainer.add(mat_features1);
bow_trainer.add(mat_features2);
Mat dictionary = bow_trainer.cluster();
bowDE.setVocabulary(dictionary);
return 0;
}
And here is how the code is compiled:
g++ BOW_creator.cpp -o BOW_creator `pkg-config --cflags --libs opencv`
Do you know what the problem could be? Can you tell me how to fix it?
Let me know if you need me to provide more information.
I have a problem in using the .inRange() method in the OpenCV.
I converted the frame to HSV and while I'm using .inRange() it doesn't filter correct color.
Can anyone help me?
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
while(true){
Mat input = imread("/home/xenups/Desktop/szpAl.png");
Mat hsv;
Mat output;
cvtColor(input, hsv, CV_BGR2HSV);
inRange(hsv, Scalar(244, 194, 194), Scalar(255, 0, 0), output);
imshow("ss",input);
imshow("redOnly", output);
waitKey(2);
}
}
I used a different scalar color Scalar(244, 194, 194), Scalar(255, 0, 0) from this site and still I have that problem.
Your Scalar values are wrong, it has max values of (179,255,255) for hsv images. Use a colour picker to determine the values you need.
I use OpenCV 2.44 and Visual Studio C++ 2010
When I compile this
#include <opencv2/imgproc/imgproc_c.h>
#include <stdio.h>
#include <math.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/legacy/legacy.hpp>
using namespace cv;
void main()
{
Mat img1 = imread( "hh.jpg", CV_LOAD_IMAGE_GRAYSCALE );
Mat img2 = imread( "hh.jpg", CV_LOAD_IMAGE_GRAYSCALE );
// detecting keypoints
FastFeatureDetector detector(15);
vector<KeyPoint> keypoints1;
detector.detect(img1, keypoints1);
// computing descriptors
SurfDescriptorExtractor extractor;
Mat descriptors1;
extractor.compute(img1, keypoints1, descriptors1);
when I run the code I get Unhandled exception at 0x580f375b in prj.exe: 0xC0000005: Access violation reading location 0x001f7014.
the error is at extractor
I'm using this tutorial link
It's looks like that you forget to init non-free module. Try to call appropriate function before using SurfDescriptorExtractor:
#include <opencv2/nonfree/nonfree.hpp>
...
cv::initModule_nonfree();
I have a program that should do template matching on an image and a template, here is the code :
int main()
{
IplImage* imgOriginal = cvLoadImage("image.jpg", 0);
IplImage* imgTemplate = cvLoadImage("template.jpg", 0);
IplImage* imgResult = cvCreateImage(cvSize(imgOriginal->width-imgTemplate->width+1, imgOriginal->height-imgTemplate->height+1), IPL_DEPTH_32F, 1);
cvZero(imgResult);
cvMatchTemplate(imgOriginal, imgTemplate, imgResult, CV_TM_CCORR_NORMED);
double min_val=0, max_val=0;
CvPoint min_loc, max_loc;
cvMinMaxLoc(imgResult, &min_val, &max_val, &min_loc, &max_loc);
cvRectangle(imgOriginal, max_loc, cvPoint(max_loc.x+imgTemplate->width, max_loc.y+imgTemplate->height), cvScalar(0), 1);
printf("%f", max_val);
cvNamedWindow("result");
cvShowImage("result", imgOriginal);
cvWaitKey(0);
return 0;
}
include files :
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include "stdio.h"
using namespace cv;
using namespace std;
When I run the code, I get this error :
templateMatching.cpp:16:75: error: ‘cvMatchTemplate’ was not declared in this scope
Any idea what the problem is? Thanks in advance, Matt
You need include
#include "opencv2/imgproc/imgproc_c.h"