Cannot build OpenCV file - opencv

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.

Related

Unable to link with opencv libraries

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.

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

Expect a type error, .pch file isn't working

I have:
#ifdef __cplusplus
#include <opencv2/opencv.hpp>
#endif
in my .pch file, but it is not being called for my .mm file.
All my "expected a type" errors go away when I have #include <opencv2/opencv.hpp> in the .mm file.
Does .mm not trigger #ifdef _cplusplus?

Windows 8 SDK renamed all headers and I don't know what to include now?

These are my headers from before I updated to the new SDK:
#pragma once
#ifndef _EXTERNAL_DEPENDENCIES_H_
#define _EXTERNAL_DEPENDENCIES_H_
#if defined(DEBUG) || defined(_DEBUG)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
#include <windows.h>
#include <time.h>
#include <mmsystem.h>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <assert.h>
#include <fcntl.h>
#include <pdh.h>
#include <stack>
#include <map>
#include <memory>
#include <random>
#include <xaudio2.h>
#include <x3daudio.h>
#include <xaudio2fx.h>
#include <ogg\ogg.h>
#include <ogg\os_types.h>
#include <vorbis\codec.h>
#include <vorbis\vorbisenc.h>
#include <vorbis\vorbisfile.h>
#include "d3dx11Effect.h"
#include <d3dx11.h>
#include <xnamath.h>
#include <dxerr.h>
#include <dinput.h>
#include <d3dcommon.h>
#include <dxgi.h>
#include <d3d11.h>
#include <d3dcompiler.h>
#include <d3dx10math.h>
#include <d3dx11async.h>
#include <D3DX11tex.h>
#include <gdiplus.h>
#pragma comment (lib, "gdiplus.lib")
#pragma comment (lib, "winmm.lib")
#pragma comment (lib, "dxguid.lib")
#pragma comment (lib, "d3dx9d.lib")
#pragma comment (lib, "d3dx10d.lib")
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "dxgi.lib")
#pragma comment (lib, "dxgi.lib")
#pragma comment (lib, "dxerr.lib")
#pragma comment (lib, "d3dx10.lib")
#pragma comment (lib, "wsock32.lib")
#pragma comment (lib, "dinput8.lib")
#pragma comment (lib, "dxguid.lib")
#pragma comment (lib, "pdh.lib")
#pragma comment (lib, "comctl32.lib")
#pragma comment (lib, "xaudio2.lib")
#pragma comment (lib, "x3daudio.lib")
#pragma comment (lib, "libogg.lib")
#pragma comment (lib, "libogg_static.lib")
#pragma comment (lib, "libvorbis.lib")
#pragma comment (lib, "libvorbisfile.lib")
#pragma warning (disable : 4482)
#endif
Atleast half of them are missing in the new SDK...
Most of the core DirectX headers are renamed, I got around that, but half of them are just missing, like Dxerr.h and d3dx11async.h and even d3dx10math.h/xnamath.h (oh and when I include DirectXMath.h it still says that XMFLOAT3 is undefined). I don't know what to do now, does it say anywhere how to migrate from the June 2010 DirectX SDK to the Windows SDK 8.0?
XMFLOAT3 in DirectXMath.h is in namespace DirectX.
Try adding the following in the header file:
using namespace DirectX;
You can also include <xnamath.h> instead of directly including <DirectXMath.h> or <D3DX10Math.h>
Have you tried the notes from http://msdn.microsoft.com/en-us/library/windows/desktop/ee663275(v=vs.85).aspx#sdk_vs11 ? especially points 5 and 7,8,9,10 are important.
grep through the new headers for functions you use from headers that are now missing. Or else MSDN documentation for the functions might tell you what header file you need.

Resources