open cv error

i cant figure out what my error is it keeps giving me the error OpenCV Error: Assertion failed ((unsigned)pt.y < (unsigned)size.p[0]) in cv::Mat::at, file c:\opencv\build\include\opencv2\core\mat.inl.hpp, line 1116

here is my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
#include <math.h>

using namespace cv;
using namespace std;

class person {
public:
	//int dir = 1;
	//int age = 0;
	int faction[3] = { rand() % 255 + 1, rand() % 255 + 1 ,rand() % 255 + 1 };
	//int strength = 1;
	//int health = 20;
	//int Fertility = 0;
	//int MutationFactor = 0;
	//bool IsSick = false;
	int x;
	int y;
	int prevx;
	int prevy;
	Vec3b prevcolor;
	void start(Mat mp) {
		x = 2;
		y = 0;
		Mat image = mp;
		namedWindow("Display window", WINDOW_AUTOSIZE);// Create a window for display.
		while (true) {
			if (x < mp.cols) {
				if (y < mp.rows) {
					image.at<Vec3b>(Point((mp.cols / 2) + prevx, (mp.rows / 2) + prevy)) = prevcolor;
					// get pixel
					Vec3b color = image.at<Vec3b>(Point((mp.cols / 2)+x, (mp.rows / 2)+y));
					Vec3b prevcolor = image.at<Vec3b>(Point((mp.cols / 2) + x, (mp.rows / 2) + y));
					// ... do something to the color ....
					color[0] = faction[0];
					color[1] = faction[1];
					color[2] = faction[2];
					// set pixel
					image.at<Vec3b>(Point((mp.cols / 2) + x, (mp.rows / 2) + y)) = color;
					imshow("Display window", image);
					waitKey(1);
					prevx = x;
					prevy = y;
					x++;
					y++;
				}
			}
		}
	}
};
Mat Map = imread("map.png");
int main() {
	person tom;
	tom.start(Map);
	return 0;
}
Last edited on
Assertion failed ((unsigned)pt.y < (unsigned)size.p[0])

Seems pt.y is >= size.p[0] which is wrong.
Set a break point at line 26 and step through it.
i believe it is having trouble loading the library
Last edited on
its not the library but i can still not figure out why this is not working
1
2
3
if (x < mp.cols) {
   //...
   image.at<Vec3b>(Point((mp.cols / 2)+x, (mp.rows / 2)+y));
you access the image as if `x' was an offset from the center
so `x' should go [-cols/2; col/2), and not [0; cols)


> Mat image = mp;
opencv Mat uses smart pointers, you need to do Mat image = mp.clone(); if you want a copy.
Topic archived. No new replies allowed.