#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv2\core\core.hpp>
#include <opencv2\objdetect\objdetect.hpp>
#include <opencv2\imgproc\imgproc.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
int i, M;
Mat ycrcb, rgb, vect, Data;
vector <String> files;
/*Names of the pictures*/
glob("C:\\Users\\lenovo\\Desktop\\cubicle\\trainning\\*.jpg", files); // M=number of training images
M = files.size();
// calculatong of the matrix Data
for (i = 0; i < M; i++)
{
// Lecture of RGB image
rgb = imread(files[i]);
namedWindow("RGB image", WINDOW_AUTOSIZE);
imshow("RGB image", rgb);
waitKey(10);
if (i == 0)
{ //for the first iteration
Mat Data(M, rgb.cols * rgb.rows * 6, CV_32FC1); //statement and allocation of matrix Data
}
rgb.convertTo(rgb, CV_32FC3, 1.0/255.0);
// Convert to float // Convert the RGB color space to the color space Ycrcbb*/
cvtColor(rgb, ycrcb, CV_BGR2YCrCb);
//making each image a vector line
rgb = rgb.reshape(1, rgb.total() * 3);
ycrcb = ycrcb.reshape(1, ycrcb.total() * 3);
/*Concatenate rgb and ycrcb*/
hconcat(rgb, ycrcb, vect);
fprintf(stdout,
"rgb=[%d,%d] , ycrcb=[%d,%d], vect=[%d,%d\n",
rgb.rows,
rgb.cols,
ycrcb.rows,
ycrcb.cols,
vect.rows,
vect.cols);
vect.copyTo(Data.row(i));
}
int nclusters = 35;
Mat labels, centers(nclusters, Data.cols, CV_32FC1);
/* clustering Data by kmeans*/
kmeans(Data,
nclusters,
labels,
TermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 0.65, 200),
3,
KMEANS_PP_CENTERS,
centers);
}
Это полный код и я получаю сообщение об ошибке:Необработанное исключение при ... Доступ чтения нарушение местонахождения
Необработанное исключение в 0x00b85c10 в PB.exe: 0xC0000005: нарушение прав доступа чтения местоположения 0xc35de59f ,
Я бы начал с включения прерывания доступа в элементе «Исключения» в меню «Отладка», а затем подошел к столу вызова к строке вашего кода, вызвав проблему. Также вы, вероятно, должны проверить, успешно ли загружены изображения. – drescherjm