Unable to link with opencv libraries - opencv

I trying use OpenCV with visual studio 2017 and running this example code is giving me build time errors
I have provided the right directories to the libraries. I have gone through many tutorials and questions/answers on stack overflow so many times but haven't succeeded in fixing the problem.
#include "opencv2\opencv.hpp"
#include "opencv2\core.hpp"
#include "pch.h"
#include "opencv2\core\core.hpp"
using namespace cv;
int main(int argv, char** argc)
{
Mat test = imread("lena.jpg", IMREAD_UNCHANGED);
imshow("tst", test);
waitKey();
}
I get the following errors
C2065 'IMREAD_UNCHANGED':undeclared identifier
C3861 'imread': identifier not found
C3861 'imshow': identifier not found
C3861 'waitkey': identifier not found
Intellisense gives me all the library suggestions when I type the code but it throws errors after build.

Related

OpenCV tries to load uninstalled Cuda dlls

I had installed CUDA 9.1 previously and tested my OpenCV with the code below, all worked fine but later on I had to remove it and install 8.0. Now the below code gives errors since the previous dlls are searched.
Here is my test code:
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/cudaarithm.hpp"
using namespace cv;
int main(int argc, char* argv[])
{
try
{
cv::Mat src_host = cv::imread("hdd.png", cv::IMREAD_GRAYSCALE);
cv::cuda::GpuMat dst, src;
src.upload(src_host);
cv::cuda::threshold(src, dst, 128.0, 255.0, cv::THRESH_BINARY);
cv::Mat result_host(dst);
cv::namedWindow("Result", cv::WINDOW_NORMAL);
cv::imshow("Result", result_host);
cv::waitKey();
}
catch (const cv::Exception& ex)
{
std::cout << "Error: " << ex.what() << std::endl;
}
return 0;
}
Here is the error:
The code execution cannot proceed because cudart64_91.dll was not found. Reinstalling the program may fix this problem.
It asks for 2-3 more dlls when I click on OK button, but I am not gonna write them here as I suspect the problem arises from the same source.
The problem is rather obvious. The dlls which are tried to be loaded, belong to the uninstalled version of CUDA (9.1), whereas I have now 8.0. I do not know why my Visual Studio 2013 tries to load the previous ones still.
Before anyone asks, yes I do have my newer installation (8.0) in my PATH. I am using Windows 10 x64, if it matters.
The real problem behind your error:
OpenCV was built with CUDA 9.1, this will not change even if you change the CUDA installation, thus it will the DLLs from CUDA 9.1 will always be required for every program that is compiled with OpenCV. Maybe a module does not have this linked and you can use it... but I am almost sure the main ones do and you won't be able to use them.
Possible solutions:
Build OpenCV with CUDA 8.0 then it will require is CUDA 8.0 DLLs and not the 9.1 ones.
Install CUDA 9.1. Both CUDA can be installed in the same computer, that is why they have this _80 or _91, this way you can have both paths and the computer decide which one is needed... I think it is not possible to have BOTH in the same program though, so be careful with this option. If it is only used by OpenCV then it will be ok.
I would recommend the first option, it is safer to stick to one library version...

OpenCV C++ using Visual Studio 2015 error

I'm a beginner to opencv, and I've been trying out some basic things using the library. I've added all the dependencies in VS, so generally the image processing related codes work. However, I am getting the following error on the console for one video-related program:
warning: Error opening file
(/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:578) Press any
key to continue.
My code is as follows:
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"
using namespace cv;
int main(int argc, char** argv) {
namedWindow("Video", WINDOW_AUTOSIZE);
VideoCapture cap;
cap.open(argv[1]);
Mat frame;
for (;;) {
cap >> frame;
if (frame.empty()) break;
imshow("Video", frame);
if (waitKey(33) >= 0) break;
}
return 0;
}
I downloaded ffmpeg, and added it my Path environment variable as well, it did not work.
I've searched quite extensively online for this, but to no avail. Any help is appreciated.

Compile a command line script for iOS

I coded an iOKit fuzzer for iOS. Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mach/mach.h>
#include <mach/vm_map.h>
#include <IOKit/IOKitLib.h>
int main()
{
io_service_t service = IOServiceGetMatching(kIOMasterPortDefault, IOserviceMatching("IOUSBHIDDriver")); // change service each time
if(!service)
{
return -1;
}
io_connect_t connect;
kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &connect);
if(kr != kIOReturnSuccess)
{
return -1;
}
uint32_t selector =3;
uint64_t input[0];
input[0] = 0x44444444444;
IOConnectCallMethod(connect, selector, input, 1, 0, 0, NULL, NULL, NULL, NULL);
printf("Did it crash? No? Do it again! -Toxic\n");
}
I've been trying to compile this with GCC for a while now, but I get all kinds of errors. I'd like to know if anyone know exactly how to compile a command line tool for iOS. Thanks.
As far as I'm aware, there's no such thing as a command line tool for (non-jailbroken) iOS, although you can output to the log using NSLog from an App. Also, Apple's toolchain for iOS uses clang (llvm) although the 'gcc' command is typically aliased to clang. The easiest way to get a script is to create a test project in Xcode, build it and look at the build log. This shows you all the commands that were run with what arguments.
Idk have you found the solution or not but anyways.
If you want to conpile with clang on device type:
clang -framework IOKit your_app.c -isysroot /var/theos/sdks/iPhoneos_whatever_sdk_you_have -o output
And this should compile.
On the mac same just without isysroot & /var...
And if you try in xcode make sure that the driver can run inside the sandbox and include iokit headers
:D

I want to put my application in waiting mode for camera connection

My small program is for read camera feed and it is working fine. But when camera connection lost during running application at that time application is terminated.Actually application control can't come out from cvCaptureFromFile() function and after some time it gives me error. When camera connection lost during running application at that time I want to control of cvCaptureFromFile() function means I want to put my application in waiting mode for next frame from camera and when got camera connection back then my application should start read frame automatically from camera. I want to do like this. I tried a lot but can't get any solution.
I am using opencv 2.4.4 version.
My cpp file is
#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
#include "stdio.h"
using namespace cv;
using namespace std;
char key;
IplImage* frame = cvCreateImage(cvSize(640,360),8,3);
int main()
{
IplImage *frame1;
back:
CvCapture* input = cvCaptureFromFile("rtsp://admin:12345#10.101.16.112:554/ch1-s1?tcp");
if(!input)
{
printf("\nWaiting for camera connection.");
goto back;
}
while(1)
{
frame1 = cvQueryFrame(input);
/*if(frame1 == NULL)
printf("\nCamera is disconnected.");*/
cvResize(frame1,frame,1);
cvShowImage("frame", frame);
key = cvWaitKey(10);
if (char(key) == 27)
break;
}
cvReleaseCapture(&input);
return 0;
}
Thanks in advance.
I don't know whether it will help you out but try this once...
1) If you are connecting camera to one of the ports, then you can continuously poll that, is it active ? and if is not active then camera got disconnected and accordingly wait for it to become active.
I think the issue might not be with the cvCaptureFromFile() function but with the frame1 = cvQueryFrame(input) command. Can you uncomment out the if statements below this command and clarify if camera disconnected is been printed out.
Sorry but can't do this myself as i currently don't have access to the opencv library

Cannot build OpenCV file

I'm trying to build this code
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int pixel;
Mat matC1_32S;
return 0;
}
and I'm getting an error:
1>c:\test1\test1\test1.cpp(21): error C2065: 'Mat' : undeclared identifier
1>c:\test1\test1\test1.cpp(21): error C2146: syntax error : missing ';' before identifier 'matC1_32S'
1>c:\test1\test1\test1.cpp(21): error C2065: 'matC1_32S' : undeclared identifier
What additional includes should I have? or somethind else?
You aren't providing a namespace for Mat. This will work if you link to the OpenCV libraries when you compile:
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {
int pixel;
cv::Mat matC1_32S;
return 0;
}
Or you can add using namespace cv; before _tmain so that you don't have to preface every appearance.
Also, you're overdoing the #include statements. You don't need the *_c.h files. (Maybe you added those when you were trying to figure out why Mat wasn't declared.)
Thank you for help, but to make it work I actually had also to include the following
#ifdef _DEBUG
#pragma comment(lib, "opencv_core231d.lib")
#pragma comment(lib, "opencv_highgui231d.lib")
#pragma comment(lib, "opencv_imgproc231d")
#pragma comment(lib, "opencv_objdetect231d.lib")
#else
#pragma comment(lib, "opencv_core231.lib")
#pragma comment(lib, "opencv_highgui231.lib")
#pragma comment(lib, "opencv_imgproc231.lib")
#pragma comment(lib, "opencv_objdetect231.lib")
#endif
I understand why I need 'using namespace cv, but why do I need this stuff with pragma, despite that I provided libraries path in the project properties. ('m using VisualStudio 10
you have to go to properties >> C/C++ >> Avanced >> Compile As and choose Compile as C++ code /TP
I did it.
It works.

Resources