opencv errors while using with windows form applications - c++

I am using opencv with visual studio 2010 windows form application c++. but it wont allow calling inbuilt functions. It gives errors like
Error 1 error C3861: 'cvCvtColor': identifier not found c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 140 1 abc
Error 2 error C3861: 'cvCvtPixToPlane': identifier not found c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 146 1 abc
I have added the following headers
#include "highgui.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
Can anyone please tell me what i am doing wrong.

Unfortunately, OP doesn't say what version of OpenCV he uses.
While working with OpenCV 3.0, use cvSplit() instead of cvCvtPixToPlane().
cvCvtColor() shall work with OpenCV 3.0, provided you added the required header files to your projects.
Finally, to make sure you don't miss any required files in your project, just start your code with #include <opencv2\opencv.hpp>.

cvCvtColor is a C API function of OpenCV, but you're intending to use the C++ one. You have 2 ways of fixing the problem:
1) (Recommended) Change your source code to use the C++ API. You should use cv::Mat instead of CvArr, cv::cvtColor instead of cvCvtColor, etc.
2) Since such changes in the source code can be pretty involved, you can still use the C API by including C-headers
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/core/core_c.h"
#include "opencv2/highgui/highgui_c.h"
instead of the C++ (*.hpp) ones

The error you've mentioned it is a linker error I suppose.
As you're including two headers highgui.hpp and highgui.h targeting to an identical library which is opencv_highgui23#.
Just include only one header.

Related

Creating a Windows shortcut (shell link) in C++

I want to programmatically create a Windows shortcut (.lnk file) to a folder. To do this, I tried this code snippet. However, I get the compilation error C2371 'WebBrowser': redefinition; different basic types in C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\exdisp.h line 2367.
Is there a C++17 std::filesystem API for this? If not, how can I fix the compilation error from above? Even with cleaned up includes, the error persists:
#include <Windows.h>
#include <shlguid.h>
#include <shobjidl_core.h>
Using the mklink command yields:
The device does not support symbolic links.
So that doesn't work either, maybe because this is an external SSD.
What else could I try?
The first answer you linked to is the correct way. And it does not rely on WebBrowser at all. It will probably help to define some of the NO_XXX macros before including windows.h.
In my version of ShlGuid.h which is slightly older than yours, I see
#ifndef NO_SHDOCVW_GUIDS
#ifndef GUID_DEFS_ONLY
#include <exdisp.h>
#include <shldisp.h>
#endif
so you can use NO_SHDOCVW_GUIDS to excise the troublesome header that you weren't wanting anyway.
If you wanted support for WebBrowser and the kitchen sink, another fix might be moving #include <windows.h> after ShlGuid.h, as shown e.g. here: https://stackoverflow.com/a/73422757/103167
Links are something that differ a fair amount from filesystem to filesystem, so difficult to standardize. Shell links (.lnk files) are filesystem-independent, but only work on MS Windows (completely non-portable) which also is a strike against finding support in a standard API.

OpenCL 2.x(C++ bindings): undefined identifier

Edit: adding OpenCL.lib in library files section of visual studio solved the problem.
With cl2.hpp from this github repository pointed by khronos site, I get 60-70 similar errors when I try to compile a C++ dll project with OpenCL-C++-implementation functions to export.
'CL_DEVICE_QUEUE_ON_HOST_PROPERTIES': undeclared identifier
// I'm not using this, I'm newly converting a v1.2 C++ binding-based
// project to a v2.0 one
starting of the file is:
using namespace std;
#define __CL_ENABLE_EXCEPTIONS
#include <CL\cl2.hpp>
and the remaining lines are not underlined with red(visual studio). There are some compile time constants I need to add maybe, but I don't know which constants.
What is missing?
this code(there isn't any other code in project) also gives same error:
#include <CL\cl2.hpp>
I had the same errors and something that worked for me was to add the following prior to #include <cl2.hpp>
#define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#include <cl2.hpp>

OpenCV "cvaux.h" equivalent

I am new to opencv and am using OpenCV 3.0.0. I found an example using include "cvaux.h". But, I want to use the new features rather than old C functions.
So, what is the equivalent hpp file for "cvaux.h"? Thanks
If your example is actually using cvaux.h, then you probably need to get a newer example. cvaux is related to obsolete C api and is now deprecated.
However, it can be found in: #include <opencv/cvaux.h>.
Note that most of the time you can just use the "include all" header: #include <opencv2/opencv.hpp>

OpenGL Linking error? Unresolved external glCreateShader()

I'm working on an OpenGL program to test out shaders and trying to compile them. However, the call to glCreateShader() (and other shader calls like glDeleteShader) give the following error:
(this error is from glCreateShader())
Error 3 error LNK2001: unresolved external symbol _pglCreateShader
I'm using Visual Studio 2012 and on windows 7. Got one of the latest nvidia cards including the latest drivers so can't be my OpenGL version.
I'm using the glTools header files for all the helper functions for the OpenGL Superbible 4th edition. Not sure if there is an error in using these files?
I'll post my includes in case this could be of any help as well.
#pragma once
#include <Windows.h>
// Basic C++ includes
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;
// OpenGL specific and GUI includes
#include "shared/gltools.h"
#include "shared/math3d.h"
#include <SOIL.h>
And linker options:
soil.lib;opengl32.lib;gltools.lib;
Oké, the problem has been solved thanks to the answers:
I edited my glTools.h to include 'gl/glew.h' instead of "glee.h", added a ;glew32.lib option to my linker and added glewInit() before entering the main loop. I've also added the GLEW libs,dlls and includes into the appropriate folder and all the functions work like they should! :)
Grab a copy of GLEW to handle extension loading.
Doing it by hand is...annoying.
On Windows, you use WGL, and when using WGL you can't just link against the GL functions directly. All the functions you get are these; you're supposed to dynamically grab the pointer to the GL entry point you want with wglGetProcAddress (as in here) before you can use them.
Basically, OpenGL on Windows is a PITA if you do the GL entrypoint function pointer loading manually. It's much easier to use a utility library to grab the pointers for you, such as GLEW.

Boost build error with websocketpp and MySQL on Windows

I am trying to build a C++ app that uses both websocketpp and MySQL. I have encountered 2 build problems using VS 2010 C++ Express.
1) A problem with the boost libraries. It produces many errors like this:
1>c:\program files (x86)\boost\boost_1_50\boost\thread\win32\thread_data.hpp(210): error C2146: syntax error : missing ')' before identifier 'rel_time'
Here's the relevant snippet from thread_data.hpp starting with line 210:
inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time)
{
interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
}
2) A conflict with the word VERSION which is documented here and I believe is independent.
To make a clear and simple example of the boost build problems, I'm using the websocketpp example: echo_server.cpp to which I added these includes:
#include "stdafx.h"
Boost lib includes recommended by "Building a program with websocketpp" on the websocketpp site.
#include <boost/regex.hpp>
#include <boost/random.hpp>
#include <boost/system/api_config.hpp>
#include <boost/system/config.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/windows_error.hpp>
and the MySQL header includes. Adding these 2 boostincludes triggers the build errors. If I comment out these 2 includes, it builds without errors:
#include <my_global.h>
#include <mysql.h>
Any suggestions on how to deal with the boost problems?
I don't think this is the same build problem as this one, "Trying to build websocket++ with MinGW: last few linker errors — what could it be?"
Concerning the first error, check if there are any macros interfering with the code. Right-click and go to definition or #define the macro yourself at the beginning of the file and see where it gets redefined. In really hard cases, look at the preprocessor output via a compiler flag.
Concerning the rest, you don't provide any versions for Boost and MySQL. Then, there is my_global.h (or is that part of MySQL?) and stdafx.h, which are both under your control but you don't show them here. Also, try to reduce the issue to the smallest possible piece of code. In short, provide a reproducible example.