Visual Studio 2010 64bit Library Build - c++

Dear StackOverFlow experts,
I have searched and searched for a solution to this problem but have not found an answer. I have found people with similar questions but not an answer. I humbly ask for your forgiveness if I have overlooked a solution. With this I ask you to please consider my submission.
I have a simple test code for OpenCV 2.4.11 in Visual Studio 2010 x64
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv2\opencv.hpp>
#include <opencv2\core\types_c.h>
using namespace cv;
int main(){
IplImage* img=cvLoadImage("C:\\Users\\Russ\\Pictures\\3-7-15\\_DSC8489.jpg"); //change the name
cvNamedWindow("Example1",CV_WINDOW_NORMAL );
cvShowImage("Example1",img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow( "Example1");
return 0;
}
When I Build this I get an error
C:\opencv\build\include\opencv2/core/types_c.h(55): fatal error C1083: Cannot open include file: 'assert.h': No such file or directory
All of the opencv includes are included in my properties path as are my libraries for OpenCV. When I open the types_c.h file I see the following
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
//M*/
#ifndef __OPENCV_CORE_TYPES_H__
#define __OPENCV_CORE_TYPES_H_
#if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER
# if _MSC_VER > 1300
# define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
# endif
#endif
#ifndef SKIP_INCLUDES
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#if !defined _MSC_VER && !defined __BORLANDC__
# include <stdint.h>
#endif
#...
Since assert.h is used for debugging, I decided to comment out the assert.h line. When I Build the code again I got this error.
C:\opencv\build\include\opencv2/core/types_c.h(56): fatal error C1083: Cannot open include file: 'stdlib.h': No such file or directory
Clearly something is not set properly for Visual Studio 2010 as it can not find these libraries. Can someone tell how to fix this problem in Visual Studio 2010 x64. Thanks for your help.

For your case, you only need to include opencv2/opencv.hpp to make it work.
Also, since you're using C++, it's strongly recommended to use OpenCV's C++ API over deprecated C API. The code will be like:
#include <opencv2/opencv.hpp>
int main()
{
cv::Mat img = cv::imread("C:\\Users\\Russ\\Pictures\\3-7-15\\_DSC8489.jpg");
cv::namedWindow("Example1", CV_WINDOW_NORMAL);
cv::imshow("Example1", img);
cv::waitKey(0);
cv::destroyWindow("Example1");
return 0;
}
Updated:
If you still encounter with problems, you should follow this post to setup OpenCV correctly with VS.

Related

How can I use input parameter as a pass to the file?

I'm a new to c++ and the task I'm currently trying to solve is to parse some data in *.txt file in one directory to the *+1.txt file in the other directory.
I've used the sample of code:
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
int main(int argc, char*argv[]){
std::ifstream input("C:\\Tmp\\example.txt");
std::string outfilepass = "";
outfilepass +=argv[2];
outfilepass +="\\";
outfilepass += argv[1];
std::ofstream outfile(outfilepass);
return 0;
}
If I compile it and then use
sample.exe example1.txt "C:\Tmp\NewFolder\" everything is works fine in windows 10, but nothing happens in windows 7.
!Update
I've found some useful links that helped me to find the solution. Problem was in target platform for the application. (I've used VS 2019). Here are some useful links:
Visual Studio 2015 Change target platform to windows 7
https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?redirectedfrom=MSDN&view=vs-2019
I've found some useful links that helped me to find the solution. Problem was in target platform for the application. (I've used VS 2019). Here are some useful links:
Visual Studio 2015 Change target platform to windows 7
https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?redirectedfrom=MSDN&view=vs-2019
The solution was build in release with
#define WINVER 0x0601 и _WIN32_WINNT 0x0601

Can't compile dll from C++ project - Visual Studio

I'm trying to play a RTSP stream in Unity 5.
For that I found a RTSP-plugin for Unity on Github that I want to try, but unfortunatelly it comes with no Readme or installation guide whatsoever.
So far I found out that I'm dealing with a C++ Visual Studio project that needs to be compiled into a DLL in order to add it to Unity. But when I try to build the project I get the following Error for the header file "ffmpegenv.h":
Error C1083 Cannot open include file: 'libavutil\opt.h': No such file or directory - (Screenshot)
Here's the code from the header file
#pragma once
//=============================
// Includes
//-----------------------------
// FFMPEG is writen in C so we need to use extern "C"
//-----------------------------
extern "C" {
//#define INT64_C(x) (x ## LL)
//#define UINT64_C(x) (x ## ULL)
#include <libavutil\opt.h>
#include <libavutil/mathematics.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
#include <libavutil/imgutils.h>
#include <libavcodec/avcodec.h>
}
I'm aware that the header includes source code from the FFmpeg libraries which doesn't come with the plugin I'm trying to compile. So I downloaded the FFmpeg source code from their GitHub page and copied all the code files (with its original folder structure) inside the plugin's project folder.
However when I then try to compile the plugin, it still doesn't find the #includes an shows the same error as mentioned above.
How I can I get the plugin to compile? What am I missing?
Thanks in advance
P.S.: I'm using Visual Studio Community 2017 with C++ support and Win 10 SDK as well as Win 8.1 SDK.

Simplest OpenCV program won't compile with error "empty attribute blocks not allowed"

In Visual Studio 2008, I am attempting to run a basic OpenCV program I found on the internet.It is the supposed to be the simplest program while still working with OpenCV. I can post the source code if needed, but the error seems to pertain to the contents of the include files.
My three includes are:
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
And the error generated when I compile is:
c:\users\noah huber-feely\documents\visual studio 2008\projects\opencvtests\opencvtests\targetver.h(10) : error C3409: empty attribute block is not allowed
The same error is generated for stdafx.h.
No other content on the web seems to have addressed this particular issue, so I am at a loss. If anyone could point me in the right direction or assist me in discovering the solution it would be much appreciated.
Here is the full source code:
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
int main ( int argc, char* arv[] )
{
IplImage *image = 0;
image = cvLoadImage("C:\Users\Noah Huber-Feely\Desktop\IMG_1484.jpg", 1);
if( image )
{
cvNamedWindow( "Input Image", 1);
cvShowImage( "Input Image", image);
printf( "Press a key to exit\n");
cvWaitKey(0);
cvDestroyWindow( "String" );
}
else
fprintf( stderr, "Error reading image\n" );
return 0;
}
Here is the content of targetver.h:
#pragma once
// The following macros define the minimum required platform. The minimum required platform
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
// your application. The macros work by enabling all features available on platform versions up to and
// including the version specified.
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
[!if DLL_APP || WIN_APP || SUPPORT_MFC || SUPPORT_ATL]
#ifndef WINVER // Specifies that the minimum required platform is Windows Vista.
#define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows.
#endif
[!endif]
#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
#endif
[!if DLL_APP || WIN_APP || SUPPORT_MFC || SUPPORT_ATL]
#ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0.
#define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE.
#endif
[!endif]

Playing cutscenes in c++

I'm using SDL for opening a window and handeling events. And OpenGL to render my objects to the screen. SDL_mixer for sound, and SDL_ttf for text. Now I'm trying to figure out how to be able to put a video on display. Like an animated logo or something before the game starts. Just to experiment with it. At some point I will need to know it...
I've found and tried installing FFMPEG, I've included the "include" folder, and set the "lib" folder. At first I got an error telling me it was unable to load "inttypes.h". So I downloaded a package with that and put it in the include folder for FFMPEG.
Now I'm stuck with this error, which I can't seem to be able to solve.
c:\program
files\ffmpeg-20140507-git-4cdea92-win64-dev\include\libavutil\common.h(87):
fatal error C1004: unexpected end-of-file found
And another question, is there other libraries aviable that may be easier to use for displaying a simple video? I read something about SDL being able to do it, but nothing was to be found about it.
EDIT: Here is line 78 to 96:
#if FF_API_AV_REVERSE
extern attribute_deprecated const uint8_t av_reverse[256];
#endif
#ifdef HAVE_AV_CONFIG_H
# include "config.h"
# include "intmath.h"
#endif
/* Pull in unguarded fallback defines at the end of this file. */
#include "common.h"
#ifndef av_log2
av_const int av_log2(unsigned v);
#endif
#ifndef av_log2_16bit
av_const int av_log2_16bit(unsigned v);
#endif
Wrap your #include <libav*.h>s inside a block like this:
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#define UNDEFINE_STDC_CONSTANT_MACROS
#endif
extern "C"
{
#include <libavdevice/avdevice.h>
#include <libavdevice/version.h>
}
#ifdef UNDEFINE_STDC_CONSTANT_MACROS
#undef __STDC_CONSTANT_MACROS
#endif
There's probably a way around using the UNDEFINE_STDC_CONSTANT_MACROS hack but the logic just isn't coming to me right now.
Worked for me on VS2012 using Zeranoe's 32-bit ffmpeg development binaries and msinttypes' inttypes.h.
Hmm, I found the DLL-files, and it gave me a linker error with the 64-bit library.
I changed back to 32-bit and the 32-bit dlls and it worked fine. I guess that libraries ask if you have 32/64-bit Visual Studio insteath of Windows.

Imread causing fatal error on the program

This should be a really straightforward question. When I run the following code:
#include "main.h"
using namespace cv;
int main( int argc, char** argv )
{
Mat image;
image = imread("C:\\Users\\Public\\Pictures\\Sample Pictures\\Lighthouse.jpg");
namedWindow("k");
imshow("k",image);
waitKey(0);
}
This error shows up when I try to run the imread line. Anyone knows what am I doing wrong here?
Thank's in advace.
Additional Info
This is being done in visual studio 2008 professional editions on a windows 7 32-bit machine.
I'm trying to debug the "Release" version.
This is the main.h file:
#pragma once
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#pragma warning( disable: 4996 )
#include <cv.h>
#include <highgui.hpp>
#include <core.hpp>
My additional include directories (Configuration Properties -> C\C++ -> General) are:
...\OpenCV2.2\include\opencv2\highgui
...\OpenCV2.2\include\opencv2\
...\OpenCV2.2\include\opencv
...\OpenCV2.2\include
The (...) are merely for my privacy, the actual code contains the full path.
My "Additional Dependencies" (Configuration Properties -> Linker -> Input) are:
"...\OpenCV 2.2.0\OpenCV2.2\lib\opencv_core220.lib"
"...\OpenCV 2.2.0\OpenCV2.2\lib\opencv_highgui220.lib"