display result of max() function with imshow in opencv - visual-studio-2010

I have 2 Mat of 1 image with a little differences in some pixels. I want to find max for each pixel and show them. I wrote this code in Visual C++ 2010 (Console):
Mat dst;
max(result0, result1, dst);
imshow("dst", dst);
and the dst image was displayed perfectly, but when I copied this code in windows form I received this error: "error C2440: '?' : cannot convert from 'cv::MatExpr' to 'bool'" so I changed the code to this:
Mat dst;
max(&result0, &result1, &dst);
imshow("dst", dst);
but in run time this error was appeared:
"An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in OpenCVProject.exe
Additional information: External component has thrown an exception."
please help me to display the image.
thanks in advance

I also met this problem.And I find it is the minwindef.h that result in this problem.so you can add this:
#undef max
#undef min
below in the header files(#include<...>),and then you can use cv::max successfully.

I think there is namespaces conflict.
Try specify namespace as below:
cv::max

As suggested by dekai adding the below but after the using namespace headers worked for me
#undef max
#undef min

Related

same code doesn't work on my own project (strcpy) in visual studio 2017

I'm working on some exercises for school.
The projects i have from my teacher work without any errors.
When i copy the code to a new project made on my computer, it shows this error:
Compiler Warning (level 3) C4996
I looked at both compiler settings and made them equal, this didn't work.
So i tried to make a project property file from my teachers project and insert it into my own project. Also this doesn't work.
Can somebody help me solving this issue?
This is the code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char s1[32];
char s2[32];
strcpy(s1, "abc def.");
strcpy(s2, "ghi_x");
printf("s1=\"%s\" en s2=\"%s\"\n", s1, s2);
printf("s1 bevat %d symbolen en s2 bevat %d symbolen\n", strlen(s1), strlen(s2));
printf("De functie strcmp(s1,s2) geeft %d als functiewaarde\n", strcmp(s1, s2));
getchar();
return 0;
}
The Error I get is
Severity Code Description Project File Line Suppression State Error C4996 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details
A quick Google search shows that "Compiler Warning (level 3) C4996" means you're using deprecated functions. The most likely culprits are your str* functions since they are generally unsafe. Switch to using their strn* counterparts (e.g. strncpy).

Expression: "(_Ptr_user&(_BIG_ALLOCATION_ALIGNMENT - 1)) ==0" && 0

I am working with Visual Studio and OpenCV. I have a simple code that detects keypoints and computes descriptors of two images.
void extractfeatures::extractKeypoints(cv::Mat _frame, cv::Mat _object)
{
//Extract keypoints
cv::Ptr<cv::FeatureDetector> detector;
cv::Ptr<cv::AKAZE> akaze = cv::AKAZE::create();
std::vector<cv::KeyPoint> object_keypoints, background_keypoints;
cv::Mat desc1, desc2;
akaze->detectAndCompute(_object, cv::noArray(), object_keypoints, desc1);
akaze->detectAndCompute(_frame, cv::noArray(), background_keypoints, desc2);
}
The code works fine and it almost the same as the one give in the OpenCV Akaze documentation: http://docs.opencv.org/3.0-beta/doc/tutorials/features2d/akaze_matching/akaze_matching.html
However, when it gets out of the function it gives me this error:
Expression: "(_Ptr_user&(_BIG_ALLOCATION_ALIGNMENT - 1)) ==0" && 0
Thank you in advance!
Because the memory of vector is limited, there are too many keypoints.
If the keypoints are about 10000:
object_keypoints.reserve(10000);
background_keypoints.reserve(10000)
Once I met such problem. It turned out that the program didn't link the right opencv's dll. When I moved the right dll, such as opencv_world310d.dll, to my program's Debug folder, this error disappeared.

Is <random> fully supported in Visual Studio 2012

I have this sample code and it throws an error:
std::random_device rd; // only used once to initialise engine
std::mt19937 rng(rd); // random-number engine used
std::uniform_int_distribution<int> uni(0, 7); // guaranteed unbiased
int random_integer = uni(rng);
The error is:
Error 1 error C2039: 'generate' : is not a member of
'std::random_device' c:\program files (x86)\microsoft visual studio
12.0\vc\include\random 1618 1 Life
Can somone explain me please, why is this happening? It seems to be an error in the header file and not in my code.
How can I fix it?
Thank you.
std::mt19937 has two constructors, one taking a single 32-bit unsigned value as parameter (default value 5489u), the other taking a seed-sequence (a template type) as a parameter. The latter is required to have a method called generate.
As a random_device does not have such a method, your code is not valid.
What you probably wanted to do is
std::mt19937 rng(rd());
That is extracting a value from the device and use that as a parameter.

matlab size function throw an exception

I'm trying to get the size of an image in matlab, here is the code:
img = imread('folder\image1.jpg');
size(img);
I'm getting this error :
"Subscript indices must either be real positive integers or logicals"
I dont know why this happens, any help to know the issue would be appreciated
Thanks,
Judging from your comments your error occurs because you overloaded the size function with a variable.

error D8016: '/ZI' and '/clr' command-line options are incompatible

I am getting the following error in my program:
error D8016: '/ZI' and '/clr' command-line options are incompatible
This happens when I put the following lines and enable common runtime in configuration->General (If I dont enable it then the error will come at using system and System::Drawing )
#using <system.drawing.dll>
using namespace System;
using namespace System::Drawing;
Actually I will be using some windows library in my code that requires the above dll.
How to solve this issue?
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/imgproc/imgproc_c.h>
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <ctype.h>
#using <system.drawing.dll>
using namespace System;
using namespace System::Drawing;
using namespace std;
int main( int argc, char** argv )
{
IplImage *source = cvLoadImage( "Image.bmp");
// Here we retrieve a percentage value to a integer
int percent =20;
// declare a destination IplImage object with correct size, depth and channels
IplImage *destination = cvCreateImage
( cvSize((int)((source->width*percent)/100) , (int)((source->height*percent)/100) ),
source->depth, source->nChannels );
//use cvResize to resize source to a destination image
cvResize(source, destination);
// save image with a name supplied with a second argument
cvShowImage("new:",destination);
cvWaitKey(0);
return 0;
}
In visual studio to turn off /ZI:
Open the project's Property Pages dialog box.
Click the C/C++ folder.
Click the General property page.
Modify the Debug Information Format property - set it to "None"
Upgrading VS will help. Minimum version: 16.11.11
In addition to what the Answer by PGP suggests, consider also changing C/C++ -> Optimization -> Optimization to Disabled (/Od).
Having it as Maximum Optimization (Favor Speed) (/O2) might give you problems when compiling for debug.
-O2 it's a certain level of compile-time optimisation. Google about what it does
In VS2017:
\ZI is set by C/C++>General>Debug Information Format = Program Database for Edit and Continue
\GL is set by C/C++>Optimization>Whole Program Optimization = Yes
I copied a configuration that I wanted to use as debug config and ran into that issue.

Resources