Eclipse OpenCV Undefined reference and Binary not found - c++

This is the code that I am trying out for a basic OpenCV program. I am using OpenCV 2.4.6.
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat im = imread(argc == 2 ? argv[1] : "lenna.png", 1);
if (im.empty())
{
cout << "Cannot open image!" << endl;
return -1;
}
imshow("image", im);
waitKey(0);
return 0;
}
Also I am using MinGW and am including the required libraries using this guide. On building all the OpenCV functions are declared as undefined references and the compilation generates the error message saying Launch failed. Binary not launched.
I checked the answer given here but on applying the changes I still cannot get it to work. Where am I going wrong?
I am using OpenCV 2.4.6 and a 64-bit windows 7.

It sounds like the compiler/linker can't find OpenCV.
Where is it installed ? Are you sure the headers and dynamic libraries are available to Eclipse ?
Are you sure you are linking against it ?

Related

How do I make a portable program with OpenCV2 on C++?

I have installed OpenCV on Windows 10 and using C++ in Visual Studio.
Now I'm trying to make a program that makes several photos then saves them.
Problem:
I made a copy of project on USB flash (go to another PC) and when I try to start it from .exe file, I get this error:
How can start it without installing 1Gb of FULL OpenCV libraries?
I tried to start from release version.
My C++ source:
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include <windows.h> // For Sleep
using namespace cv;
using namespace std;
int main(int, char**)
{
VideoCapture cap(0);
// Get the frame
Mat save_img; cap >> save_img;
if (save_img.empty())
{
std::cerr << "Something is wrong with the webcam, could not get frame." << std::endl;
}
// Save the frame into a file
imwrite("test.jpg", save_img); // A JPG FILE IS BEING SAVED
return 0;
}
My settings:
P.S. I want to make light program for making photo on Windows. And how to make real portable programs.

OpenCV imread could not open or find image

I'm doing a project with OpenCV. I am trying to run a simple code:
#include<opencv2/core.hpp>
#include<opencv2/videoio.hpp>
#include<opencv2/highgui.hpp>
#include<opencv2/imgproc.hpp>
#include<opencv2/opencv.hpp>
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
cv::Mat img2 = cv::imread("test.jpg", 1);
if (!img2.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
cv::waitKey(5000);
return -1;
}
else {
cout << "Working" << endl;
cv::waitKey(5000);
}
return 0;
}
My project is a lot more bigger then this, however something simple like this isn't working for me. I have tried many things such as full path names // and \\, even tried an IplImage and convert it into Mat still no luck.
I have tried many different file types as well. If it helps I have coded it to stop the application after hitting any button, that does not work as it isn't taking any input from my keyboard.
How can I determine what is wrong?
I had this exact issue including the part about it only working in release mode. I found out I was using the release libraries for both release and debug. Because I had followed the tutorial on the OpenCV website for visual studio (incorrectly albeit), I changed the .lib folder to the correct d.lib and that fixed it.

Visual Studio 2015 OpenCV Assertion failed (size.width>0 && size.height>0) in cv::imshow windows.cpp

I've been learning a bit of c++ lately and i keep getting the same error for some reason.
Apparently, imshow isn't able to find the file.
My codes are
#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include<iostream>
#include <conio.h>
using namespace std;
using namespace cv;
int main()
{
cv::Mat img;
img = imread("1.png");
if (img.empty())
{
cout << "can't find da file\n\n" ;
}
cv::namedWindow("test");
cv::imshow("test",img);
waitKey(0);
}
I've tried putting it in the project folder along with the ".exe",
I tried listing the whole directory of the image using "/" and "\"
I've also tried not using any extensions in the code but to no avail.
Error Signs
Thanks for helping you guys :)
I always advise the same thing for these cases. It just needs a little lateral thinking. Change your code to this
int main()
{
ofstream test("test.txt");
test << "I'm here!!\n";
}
Now run this program, it will create a file called test.txt. Find out where that file is on your system and that's where you should put your 1.png file. Then you can go back to your original program confident that the file is in the right place and any remaining issues are a different problem.

Opencv << operator error for cout and writing to FileStorage

I am having problems getting the << operator to work for cout and writing to a FileStorage object in Visual studio c++ 2010 express. I am using the vs10 libraries, included the ***d.lib files and am running my project in debug mode. Other opencv functions (ORB, imshow) seem to work
When I use the << operator for printing a matrix with cout I get an access violation error.
The second issue I am having is when I try to write a matrix to a FileStorage object. I can write 1 matrix and read it from the file without it crashing. When I however try to write 2 matrices I get an "Exception at memory location" error on the second write. The console error says that No element name has been given.
The code I used for testing:
cv::Mat test(3,3,CV_8UC1);
cv::FileStorage file("fudge.xml", cv::FileStorage::WRITE);
for(int x=0;x<3;x++){
for(int y=0;y<3;y++){
test.at<unsigned char>(x,y) = x+y;
}
}
std::cout<<test<<std::endl;
file << "rotMat1" << test;
file << "rotMat2" << test;
Code Update
this is my entire code
#include "stdafx.h"
#include <opencv2\core\core.hpp>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
cv::Mat test(3,3,CV_8UC1);
cv::Mat test2(3,3,CV_8UC1);
cv::FileStorage file("fudge.xml", cv::FileStorage::WRITE);
for(int x=0;x<3;x++){
for(int y=0;y<3;y++){
test.at<unsigned char>(x,y) = x+y;
test2.at<unsigned char>(2-x,2-y) = x+y;
}
}
std::cout<<test<<std::endl; //error 1
file << "AAAAA" << test;
file << "BBBBB" << test2; //error 2
return 0;
}
both errors still occur
UPDATE, I fixed it (kind of)
I found the problem but now there is a new one. So the problem was that because I have projects in both VS2010 and VS2012. Because of this I added both vs10/bin and vs11/bin to the path variables. It turns out that this results in visual studio using vs11/bin (maybe because that was declared first). After removing the vs11/bin decleration it worked in vs2010 but now vs2012 is broken. Because this isn't part of the original problem I will set it as answered.
The problem was that because I have projects using opencv in both visual studio 2010 and 2012 I added both /dir paths to the environment path variable. This resulted in visual studio always using the 2012/dir (probably because this was declared first). After removing the 2012/dir it worked fine.
you need to add using namespace cv;
follow this exemple : http://docs.opencv.org/modules/core/doc/xml_yaml_persistence.html#xml-yaml-file-storages-writing-to-a-file-storage
I don't think the namespace is the problem.
Two things that I could think off that cause the problem:-
did you release your file object?
In the XML file, both your entries would have the same field. I'm not sure if this is supported by XML filestorage in Opencv. Did you try writing twice with different Mat objects?

VideoWriter not working on Win7-64Bit VM

I coded the below which tries to hold a picture and count number hundred and finally grab all them to a video with following codec MP42(MPEG4-V2)
#include <stdAfx.h>
#include <iostream>
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
int n=0;
char a;
int main(int, char** argv)
{
Mat image= imread("C:\\Users\\Metin\\Desktop\\images.jpg");
Mat newimage;
VideoWriter vide ("Hopdedik.avi",CV_FOURCC('M','P','4','2'),30.0,image.size());
vide.open("Hopdedik.avi",CV_FOURCC('M','P','4','2'),30.0,image.size());
for(int n=0; n<100;n++){
cout<<n<<'\n';
std::string s= to_string(static_cast<long long>(n));
image.copyTo(newimage);
putText(newimage,s,Point(100,40),cv::FONT_HERSHEY_COMPLEX,2,cv::COLORMAP_COOL,2,2,false);
imshow("asd",newimage);
if(!vide.isOpened())cout<<"can not opened";
vide.write(newimage);
waitKey(10);
}
vide.release();
return 0;
}
I started debugging on Release mode and copied the .exe files to Virtualbox Win7-64 bit. Right after I put necessary .dll files exe works but the code can't properly create the video.
I have tried to install following two codecs:
http://www.fourcc.org/downloads/angel-potion-mpeg-4--8/
and Indeo which is: http://www.afreecodec.com/codec-by-code/iv45-160.html
But it did not work.
Once I faced a similar problem where opencv couldn't read a video. There was no warning at all. The reason was that an automated string maker resulted in "opencv_mmpeg.dll" which was missing from the system. So, I debugged up to cap_ffmpeg.cpp and found this:
#if defined WIN32 || defined _WIN32
const char* module_name = "opencv_ffmpeg"
CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION)
#if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__)
"_64"
#endif
".dll";
So, copy opencv_ffmpeg_64.dll to your folder and you might have some results. Else, you need to debug deeply. Start by inserting into your project the file opencv/modules/highgui/src/cap.cpp (and the headers needed to be compiled) so you can debug line by line. I suppose many other files will be needed to go further down into the code.