Accessing the elements of a Mat variable
Hi, I´m gonna find the maximum and the minimum value of an image pixels: // ConsoleApplication1.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
int main()
{
Mat img1;
double minVal, maxVal;
int minLoc[2], maxLoc[2];
img1 = imread("DCIM_20171025_1.JPG");
namedWindow("Test Image", WINDOW_AUTOSIZE);
imshow("Test Image", img1);
waitKey(0);
minMaxIdx(img1, &minVal, &maxVal, minLoc, maxLoc);
printf("MAX= %d, MIN= %d", maxVal, minVal);
getch();
return 0;
}
It seems pretty easy, but it doesn´t work! The program is compiled successfully, but there´ll be a run time error: Unhandled exception at 0x00007FF9E3EB9E08 in ConsoleApplication1.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000C981CFF3C0. occurred Does anyone know how to solve this problem? Thank you