Vision Tracking imaqMorphology exception

Hi, we have been having trouble getting vision tracking, and our problem is at the step in which when we are taking away small objects.

Here’s our code:


AxisCamera& camera = AxisCamera::GetInstance("10.13.34.11");
	if (camera.IsFreshImage())
	{
		int low = 125;
		int high = 255;
		StructuringElement* sElement;
		sElement->matrixCols = 3;
		sElement->matrixRows = 3;
		sElement->hexa = FALSE;
		HSLImage* image = camera.GetImage();
		MonoImage* luminance = image->GetLuminancePlane();
		image->ReplaceRedPlane(luminance);
		image->ReplaceGreenPlane(luminance);
		image->ReplaceBluePlane(luminance);
		BinaryImage* bImage = image->ThresholdHSL(low, high, low, high, low, high);
		BinaryImage* bImage1 = new BinaryImage();
		imaqMorphology(bImage1 -> GetImaqImage(), bImage -> GetImaqImage(), IMAQ_ERODE, sElement);
		delete bImage;
		BinaryImage* bImage2 = new BinaryImage();
		imaqMorphology(bImage2 -> GetImaqImage(), bImage1 -> GetImaqImage(), IMAQ_ERODE, sElement);
		delete bImage1;
		BinaryImage* bImage3 = new BinaryImage();
		imaqMorphology(bImage3 -> GetImaqImage(), bImage2 -> GetImaqImage(), IMAQ_ERODE, sElement);
		delete bImage2;
		BinaryImage* bImage4 = new BinaryImage();
		imaqMorphology(bImage4 -> GetImaqImage(), bImage3 -> GetImaqImage(), IMAQ_ERODE, sElement);
		delete bImage3;
		BinaryImage* bImage5 = new BinaryImage();
		imaqMorphology(bImage5 -> GetImaqImage(), bImage4 -> GetImaqImage(), IMAQ_DILATE, sElement);
		delete bImage4;
		BinaryImage* bImage6 = new BinaryImage();
		imaqMorphology(bImage6 -> GetImaqImage(), bImage5 -> GetImaqImage(), IMAQ_DILATE, sElement);
		delete bImage5;
		BinaryImage* bImage7 = new BinaryImage();
		imaqMorphology(bImage7 -> GetImaqImage(), bImage6 -> GetImaqImage(), IMAQ_DILATE, sElement);
		delete bImage6;
		BinaryImage* bImage8 = new BinaryImage();
	    imaqMorphology(bImage8 -> GetImaqImage(), bImage7 -> GetImaqImage(), IMAQ_DILATE, sElement);
	    delete bImage7;
		vector<ParticleAnalysisReport>* particles = bImage -> GetOrderedParticleAnalysisReports();
		cout << particles->size() << endl;
		delete particles;
		delete bImage8;
		delete luminance;
		delete image;
	}

Our problem is at the imaqMorphology functions. It looks weird because this is our most recent try at fixing it. The code compiles successfully, but gives this error in the console, and prevents the robot from running.

0x2a8cda8 (FRC_RobotTask): memPartAlloc: block too big 3913540616 bytes (0x8 alig
in partition 0x34f600
0
Default TeleopContinuous() method… Overload me!
0x2a8cda8 (FRC_RobotTask): memPartAlloc: block too big 3368229384 bytes (0x8 alig
in partition 0x34f600

program
Exception current instruction address: 0x00000000
Machine Status Register: 0x0008b012
Condition Register: 0x28000828
Task: 0x2a8cda8 “FRC_RobotTask”
0x2a8cda8 (FRC_RobotTask): task 0x2a8cda8 has had a failure and has been stopped.
0x2a8cda8 (FRC_RobotTask): fatal kernel task-level exception!

The first block of the error sometimes repeats itself over and over again.

We have looked at the java version for vision tracking, but it doesn’t really help us as some of the functions in java aren’t in c++.

Thank you very much.

The ImaqMorphology function’s first two parameters are pointers to Image objects. The first Image is the destination image, and the second is the source image. The function morphs the second image and puts the changed image for the first parameter. I think the problem we have is that we do not actually pass in the object itself, and instead, passes in a temporary object. We have tried creating Image objects so that we pass in the object itself, but when we tried to define an Image object, it gives an error saying that it’s an incomplete type.

That looks like the problem. To create an image, you need to use the imaq or frc function. Try this instead:

Image* processedImage = imaqCreateImage(IMAQ_IMAGE_U8, 3);
imaqMorphology(processedImage, bImage -> GetImaqImage(), IMAQ_ERODE, sElement);

When you wish to dispose of the image, you can then use

imaqDispose(processedImage);

It fixed the problem. Thank you.