I want to create a matrice in opencv for my project of raytracing.
This is the code I have come up:
#include "Windows.h"
#include "core/mat.hpp"
#include "core/core.hpp"
#include "core/types_c.h"
using namespace cv;
Mat createImage()
{
Mat b(480, 640, CV_8UC3);
return b;
}
And I have problem with the two Mat. It says variable has incomplete type "cv::Mat". I can't understand what it means. I always wrote only Mat nothing else.
Can someone help me please?
Just include "opencv2/core/core.hpp".
You can use below example code.
#include "opencv2/core/core.hpp"
using namespace cv;
Mat createImage()
{
Mat b(480, 640, CV_8UC3);
return b;
}
int main()
{
createImage();
}
You only need to '#include "core/core.hpp"`
The compiler needs to be able to find the include files, do you have Opencv/Include in the compiler's include directory list? Did it give any error about finding core.hpp?
Related
I wrote a very simple program with opencv
and I get this problem ( I'm using TDM-GCC x64 compiler)
cannot find c:/opencv/opencv2/build/x64/lib permission denied
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main (){
Mat image =imread("An0nymOu5.jpg");
namedWindow("image",cv::WINDOW_FREERATIO);
imshow("image",image);
waitKey(0);
}
Could be a compiler error; you can try in this link to find the toolchain
mingw-w64
Also assure the image file is near your program file.
try this aswell.
Mat image;
image = imread("An0nymOu5.jpg", CV_LOAD_IMAGE_COLOR);
Following code results in build success, but no window. Without "m = Scalar(255,0,0);", it creates black window. Why including scalar does not work?
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace std;
int main() {
Mat m = Mat::zeros(200,200,CV_8UC3);
m = Scalar(255,0,0); //without this, it creates window.
imshow("m", m);
waitKey();
}
It will not give you any compilation error as Mat and Scalar are basically array types of OpenCV.
This is a possible duplicate of How to set all pixels of an OpenCV Mat to a specific value?
Your code have to work!
take a look at the doc:
C++: void imshow(const string& winname, InputArray mat)
and I can confirm you is working fine on my environment(opencv320, VisualStudio2017):
you need to clean the project and build again.
I'm new to opencv library and every time i try to compile This code
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgcodecs.hpp"
using namespace cv;
using namespace std;
int main()
{
Mat img;
img = imread("lena.jpg");
imshow("Original Image", img);
waitKey();
}
I get This error undefined reference to `__atomic_fetch_add_4
This code is copied from a tutorial and It's was working with its writer so the problem is definitely with me
I looked for a solution for this problem to much and I did not found any working solution, I do not even no what is the cause of the problem
I'm using Code::Blocks IDE
Thanks,
Go to Setting>Compiler Settings and tick the Intel i486 option. It worked for me
I am working in Motion Detector Script but when i run my code i get this error every time when i use this function, but i don't know why it's wrong.
I am using opencv3, below is my code. I tried to run other examples i get it from web to same function, but the error still there. Any idea to fix it ?
This is the Error:
cv.cpp: In function ‘int main()’:
cv.cpp:23:4: error: ‘BackgroundSubtractorMOG’ is not a member of ‘cv’
My code :
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <vector>
#include <iostream>
#include <sstream>
#include <opencv2/video/background_segm.hpp>
using namespace std;
int main()
{
//Openthevideofile
cv::VideoCapture capture("/home/shar/Desktop/op.mp4");
//checkifvideosuccessfullyopened
if (!capture.isOpened())
return 0;
//currentvideoframe
cv::Mat frame;
//foregroundbinaryimage
cv::Mat foreground;
cv::namedWindow("ExtractedForeground");
//TheMixtureofGaussianobject
//used with all default parameters
cv::BackgroundSubtractorMOG mog;
bool stop(false);
//forallframesinvideo
while(!stop){
//readnextframeifany
if(!capture.read(frame))
break;
//updatethebackground
//andreturntheforeground
mog(frame,foreground,0.01)
//learningrate
//Complementtheimage
cv::threshold(foreground,foreground,128,255,cv::THRESH_BINARY_INV);
//showforeground
cv::imshow("ExtractedForeground",foreground);
//introduceadelay
//orpresskeytostop
if(cv::waitKey(10)>=0)
stop=true;
}
}
As #shar said, the answer is in this post. In order to create a smart pointer to the algorithm you need to do:
cv::Ptr<cv::BackgroundSubtractorMOG2> pMOG2 = cv::createBackgroundSubtractorMOG2();
EDIT:
And for use the algorithm:
float learningRate = 0.01; // or whatever
cv::Mat foreground;
pMOG2->apply(frame, foreground, learningRate);
Hello I am trying to implement a Fast Feature Detector code,in the initial phase of it i get the following errors
(1)no instance of overloaded function "cv::FastFeatureDetector::detect" matches the argument list
(2)"KeyPointsToPoints" is undefined
Please help me.
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
using namespace cv;
int main()
{
Mat img1 = imread("0000.jpg", 1);
Mat img2 = imread("0001.jpg", 1);
// Detect keypoints in the left and right images
FastFeatureDetector detector(50);
Vector<KeyPoint> left_keypoints,right_keypoints;
detector.detect(img1, left_keypoints);
detector.detect(img2, right_keypoints);
vector<Point2f>left_points;
KeyPointsToPoints(left_keypoints,left_points);
vector<Point2f>right_points(left_points.size());
return 0;
}
The problem is in this line:
Vector<KeyPoint> left_keypoints,right_keypoints;
C++ is case-sensitive, it sees that Vector is something different than vector (what it should really be). Why would Vector work is beyond me, I would have expected an error earlier.
cv::FastFeatureDetector::detect only knows how to work with vector, not a Vector, so try to fix this bug and try again.
Also, KeyPointsToPoints does not exist in the OpenCV library (unless you program it yourself), make sure you use KeyPoint::convert(const vector<KeyPoint>&, vector<Point2f>&) to do the conversion.
There are a few small problems with the code as given. First you are missing using namespace std which is needed to use the vectors the way you are using them. You are also missing the include for vectors #include <vector>. vector<KeyPoints> should also have a lower case v. I'm also not sure if KeyPointsToPoints is part of OpenCV. You may have to implement this function on your own. I'm not sure, I just haven't seen it before.
#include <stdio.h>
#include <vector>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
using namespace cv;
using namespace std;
int main()
{
Mat img1 = imread("0000.jpg", 1);
Mat img2 = imread("0001.jpg", 1);
// Detect keypoints in the left and right images
FastFeatureDetector detector(50);
vector<KeyPoint> left_keypoints,right_keypoints;
detector.detect(img1, left_keypoints);
detector.detect(img2, right_keypoints);
vector<Point2f>left_points;
for (int i = 0; i < left_keypoints.size(); ++i)
{
left_points.push_back(left_keypoints.pt);
}
vector<Point2f>right_points(left_points.size());
return 0;
}
I didn't test the code above. Check out the OpenCV documentation here