Image Cropping/Mask?

Hi-

I am trying to crop out a certain part of an image to process.
I am able to create a region of interest, but when i try to crop out the rest of the picture, I can’t seem to do it.

This is the relevant part of my code:

ROI* roi;
roi = imaqCreateROI();
imaqAddRectContour(roi,imaqMakeRect(0,0,220,640));

It is at this point I get stuck. I plan on using the imaqROIToMask function, but I can’t get it to work.

This is what I am doing-


ROI* roi;
roi = imaqCreateROI();
imaqAddRectContour(roi,imaqMakeRect(0,0,220,640)); //top of image
ColorImage* origImage = camera.GetImage();
ColorImage* croppedImage;
imaqROIToMask(????????);

At the imaqROIToMask line I get errors no matter what I try to do.

Basically I just want the camera tracking/processing code to only look in a certain portion of the image. Sadly I couldn’t find a “crop” function in the nivision.h library.

Thanks!

It kinda seems like you’re heading for unnecessary complication. Can you tell me why you want to crop and only look at a portion of the image? Since you don’t know where the targets will be in relationship to the camera at any given time, it seems to me that you want to have as much of the image as possible for doing the analysis and finding targets.

bob

For faster image processing. Changing out camera resolution from 640x480 to 320x240 dramatically increased our speed, but with reduced accuracy due to the lower number of available pixels.
By using a high resolution image but using a mask we keep the accuracy white the mask improves the speed.
As for location of the target, that isnt a problem.

I’m not near my Windows laptop so I am running blind at the moment. I see your purpose though. So - my initial suggestion would be to go to NI Vision Assistant and generate a script which captures at 640x480 and then crops it. Generate the C code for this and that should fill in the gaps for you.

Report back! Interested to hear if that gives you what you need and also whether it works. If that doesn’t help, I’ll be able to take a deeper look this evening.

bob

Interesting… We don’t have accuracy issues with 320x240. What kind of inaccuracy are you seeing? Too many false positive particles? In any case, I suspect if you tune the filters correctly, you will increase your accuracy. This may be easier than trying to crop the image.

For accuracy issues-
It isnt being inaccurate per se, but a higher resolution would allow for higher accuracy, no? More pixels to count and line up with?

For using the NI Vision Assistant-
We have. I copied the C code, but it is throwing errors. I dont have access to it right now, but I will post it when I can.

How accurate is the shooter? While it is true that a 640x480 image has more information, it is four times as much data and will generally take about 4x the processing time. You shouldn’t really need to crop – that is equivalent to using an ROI, but the ROI doesn’t need to copy the data to a new image, etc.

If you do a bit of math, you can determine how much error a single pixel of error represents, and unless you are shooting from mid-court with a very accurate shooter, I wouldn’t think it would matter.

Also, keep in mind that floppy cameras don’t take very good images or give very accurate numbers. I’m not saying anything about your mounting, but in the reveals, I’ve seen some that are practically zip-tied on and are flopping all about.

We have the camera mounted pretty securily, using the bolt on it, that isn’t an issue, (unless we start hitting 6.5K RPM…)
The shooter itself is fairly precise, hitting within less than 1 foot consistently.

We used camera tracking code to rotate our turret head, and using the same algorithim for rotation, with the higher resolution image it would take too long to process and start to overshoot. When we used the same algorithim and a smaller resolution image, it locked in without any osiciallation.

We calcuated the whole 4x less data to process also, but we feel it will be worth having the higher resoultion to process with, in order to gain distance and more accurate lock on with the camera.

The C code that NI Vision Assisstant created is throwing an error, something about one of the imaq functions not being correct. I will try and get that posted within 2 hours.

Because of the fact that the vision library only gives the bounding box of the rectangular target. It is by definition inaccurate IMHO. If you have any perspective distortion, I suspect the center_mass_x/center_mass_y are going to have some amount of error anyway. So a few pixel error due to resolution is probably insignificant if your robot is close enough to the targets. If your robot is far enough, there are a lot more factors affecting your accuracy (e.g. the precision of your PID controlled turn, the variation of the shooter speed, air resistance etc.).

You’re probably right, I think we will stay with a 320x240 image.

Thanks!

The example code uses the bounding box as an approximation.

If you want to make a multi-pass measurement, once you have the bounding box, you can reinspect the blob, or perhaps the original image to locate the precise edges. Doing the edge detection on the entire image is expensive. Doing it on the area known to contain the target should be pretty cheap. Personally, I think the example code should be careful not to solve too much of the problem.

Back to the original problem, again, it this instance, you shouldn’t really need to crop or copy the image, but you should normally be able to use an RIO that is constructed from the rectangle, mask, or other geometric info.

Greg McKaskle

We decided to just crop the image on the camera itself.

We put an image overlay over everything except the area we want to process. Even though the image is still the same size, we think it will take less processing time, since the rest of the image is the same and not changing.

Either way, we got it to work.

Thanks!