error: putText is not a member of CV? - c++

I can not use the function putText. I get the compilation error "putText is not member of CV" or "putText is not declared in this scope".
These are the libraries I am including:
#include <iostream>
#include "core.hpp"
#include "highgui.hpp"
#include "imgcodecs.hpp"
#include "cv.h"
and that's how I am calling it:
cv::putText(frame,"REC",Point(0,60),2,2,Scalar(0,0,255));
what am I doing wrong?

putText has been moved to imgproc module in OpenCV 3 (previously it was in core module).
So you need to:
#include "imgproc.hpp"
You can include opencv.hpp to avoid this kind of problems, since it will include all headers for you.

Related

How to properly include headers and use STL vector in c++ app?

I decided to try STL and use a vector instead of a custom made growable array class. The problem is that I can't get anything to compile. If I do something like this:
#include "stdafx.h"
#include <vector>
std::vector<PITEMID_CHILD> APIDL;
I get a bunch of messages similar to this:
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\cstdint(23): error C2039: 'int_least8_t': is not a member of '`global namespace''
If I change to this:
#include <vector>
#include "stdafx.h"
std::vector<PITEMID_CHILD> APIDL;
I get this:
1>x:\win32testing\vectortest\vectortest.cpp(4): error C2039: 'vector': is not a member of 'std'
Inside of stdafx.h is this:
#pragma once
#include <windows.h>
#include "targetver.h"
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <shlobj.h>
#include <exdisp.h>
#include <shellapi.h>
#include <shlwapi.h>
#include <atlbase.h>
#include <atlalloc.h>
#include <CommonControls.h>
// reference additional headers your program requires here
#include <CommCtrl.h>
Any idea what is going on?
From wikipedia documentation:
Visual C++ will not compile anything before the #include "stdafx.h" in the source file, unless the compile option /Yu'stdafx.h' is unchecked (by default); it assumes all code in the source up to and including that line is already compiled.
The best solution is to get rid of precompiled headers.
And for your C2039 error, it doesn't seem to be a result of line std::vector<PITEMID_CHILD> APIDL;. int_least8_t is a type defined in cstdint (stdint.h). It seems you haven't included this header file in your project.

C++ Boost and ImageMagick++ API issue

While developing Raspberry Pi library compiled by g++4.9.2 I have met compability issue between boost (1.6.2) and ImageMagick++ API (7.0). When compiling this code:
#include <Magick++.h>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
I got these boost errors:
__assert_fail was not declared in this scope (path_trails.hpp)
...
__assert_fail was not declared in this scope (path.hpp)
...
__assert_fail was not declared in this scope (shared_ptr.hpp)
When deleting #include <Magick++.h> line everything runs fine. Unfortunately I need boost and ImageMagick as well in this source file. How to solve this issue?
A simple workaround is to include Magick++.h after boost.
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <Magick++.h>
I don't have a proper explanation for this problem but it seems to come from a clash when using different headers including assert.h (I had the same problem using the assimp library and ImageMagick) but I don't get why the order matters.
Reproducing your case, assert.h is included in:
cassert for boost
MagickCore/pixel-accessor.h for Magick++.h
If someone has an explanation for this problem feel free to edit.

Linux: Conflicts using inotify with fcntl

I'm having a strange linking issue after I included inotify in my program to monitor changes to a filesystem. The project includes <fcntl.h> in many other source files. However, when I include <sys/inotify.h> in the source file which is doing the directory monitoring, I get this error:
/usr/include/fcntl.h:30:1: error: expected initializer before ‘extern’
__BEGIN_DECLS
My project uses CMake, although that doesn't seem to be relevant for finding inotify. It IS finding the inotify declarations to my knowledge, since when I included , it threw an error that inotify_init() and the other functions I used were not defined. Inotify includes fcntl and is partially built on top of some of the functionality there, so my first thought was that it's importing a different version of fcntl than the rest of my program.
In ObjectManager.h:
#ifndef MANAGE_OBJECT_H
#define MANAGE_OBJECT_H
#include "config.h"
//includes all lua headers under extern 'C'
#include <lua.hpp>
#include <list>
#include <unordered_map>
#include <pthread.h>
class ObjectManager //...
The only thing that changed was ObjectManager.cc, with the addition of sys/notify and the implementation of the watcher (not included because this is a linking issue):
#include "config.h"
#include "ObjectManager.h"
#include "Control.h"
#ifdef OBJECT_MANAGER_ENABLED
#include <string.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>
#include <unistd.h>
#include <fstream>
#include <sys/inotify.h>
//... inotify implementation
Where Control.h declares #include <fcntl.h>.
This is the closest issue I found, related to some problems in the implementation of different fcntl headers for userspace usage. https://lkml.org/lkml/2008/9/16/98
The same problem occurs on Linux 2.6 running on Centos 6 and Linux 4.0 running on Centos 7.
Any ideas on what is causing this error and how to successfully include inotify?
Resolution: A function definition lacked a semicolon at the END of ObjectManager.h right before a #endif, and the resulting GCC error that propagated through the next includes in a complicated manner, resulting in a strange preprocessor error in fcntl.h.

What to include for cv::meanShift function?

I've included the following and it doesn't work :
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
What to include for cv::meanShift function ?
it's in the video module, so:
#include <opencv2/video/video.hpp>
2 hours later I found the answer :)
For some reason #include can't be included directly so the following code will include the video module indirectly.
#include "opencv2/video/tracking.hpp"
#include "opencv2/video/background_segm.hpp"
Answer here : http://fossies.org/dox/opencv-2.4.9/video_8hpp.html

SHGetSpecialFolderPath() Not Declared in This Scope

I am not able to compile my program SHGetSpecialFolderPath() not being declared in the scope of the program, while the correct header is being included (according to MSDN)
http://msdn.microsoft.com/en-us/library/bb762204(v=vs.85).aspx
Here are the headers for my project:
#include <iostream>
#include <iostream>
#include <windows.h>
#include <algorithm>
#include <vector>
#include <fstream>
#include <direct.h>
#include <shlobj.h>
With error:
C:\Users\user\Documents\getAppData\main.cpp|31|error: `SHGetSpecialFolderPath' was not declared in this scope
with shlobj.h being the header with the declaration in it.
Any ideas why the compiler is throwing the error? Here is how I am calling the function:
char appData[MAX_PATH];
SHGetSpecialFolderPath( NULL
,appData
,CSIDL_LOCAL_APPDATA
,1 );
cout << appData << endl;
Thanks!
From the MSDN page:
The Microsoft Internet Explorer 4.0
Desktop Update must be installed for
this function to be available.
With Windows 2000, this function is
superseded by ShGetFolderPath. You can
use this function on earlier systems
by including the redistributable DLL,
ShFolder.dll.
Perhaps this is your problem?