Log in or register to post comments

Objects detection inside markers

December 22, 2011 - 2:35am #1

Hi,

I'm new in AR and I wanted to know if there were algorithms to detect circles.
My scene is the following : I have to detect 9 small circles and tell if they are black or whites.
I guessed the optimized solution is to put the circles inside a marker and do some image processing after QCAR has detect the marker. Is it actually something QCAR can do ? If yes, can anyone give me a hint of existing algorithms ?

Thanks and sorry for the trivial questions but as I said, I'm new in AR.

Re: Objects detection inside markers

January 7, 2012 - 4:47am #13

The result is perfect. Thanks Kim for taking the time to help me !

- DaProd

Re: Objects detection inside markers

January 6, 2012 - 9:54pm #12

Okay, turns out I was wrong! glReadPixels works on the frame buffer, which does match the screen size, with 0, 0 in the lower left. Here's a function that can take the camera point to frame buffer space:

- (QCAR::Vec2F)cameraPointToFramebufferPoint:(QCAR::Vec2F)cameraPoint
{
    // Note this function assumes landscape orientation
    
    QCAR::VideoMode videoMode = QCAR::CameraDevice::getInstance().getVideoMode(QCAR::CameraDevice::MODE_DEFAULT);
    QCAR::VideoBackgroundConfig config = QCAR::Renderer::getInstance().getVideoBackgroundConfig();
    
    int xOffset = ((int) framebufferWidth - config.mSize.data[0]) / 2.0f + config.mPosition.data[0];
    int yOffset = ((int) framebufferHeight - config.mSize.data[1]) / 2.0f - config.mPosition.data[1];
    
    QCAR::Vec2F fbPoint = QCAR::Vec2F(cameraPoint.data[0] * config.mSize.data[0] / (float) videoMode.mWidth + xOffset,
                                      cameraPoint.data[1] * config.mSize.data[1] / (float) videoMode.mHeight + yOffset);
    
    // Camera origin is upper left, while framebuffer origin is lower left
    fbPoint.data[1] = framebufferHeight - fbPoint.data[1];
    
    return fbPoint;
}

Given that, I was able to get reasonable values from your target with this code:

for (int h = 2; h <= 3; h++) {
    for (int j = 1; j <= 4; j++) {
        pixelPointMarker = CGPointMake(-15.0 + 6.1 * h, -15.0 + 5.9 * j);
        QCAR::Vec2F cameraPoint = QCAR::Tool::projectPoint(cameraCalibration, pose, QCAR::Vec3F(pixelPointMarker.x, pixelPointMarker.y, 0));
        QCAR::Vec2F framebufferPoint = [self cameraPointToFramebufferPoint:cameraPoint];
        glReadPixels(framebufferPoint.data[0], framebufferPoint.data[1], 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelColor);
        NSLog(@"pixelColor: %d, %d, %d", (int) pixelColor[0], (int) pixelColor[1], (int) pixelColor[2]);
    }
}

Let me know if that works any better for you.

- Kim

Re: Objects detection inside markers

January 6, 2012 - 3:55am #11

Thanks for helping me kim, I really appreciate.

It is really random. It can pass from black to white at any time and I don't know why.

My code is :
[CODE" />CGPoint pixelPointMarker;

const QCAR::CameraCalibration& cameraCalibration = QCAR::Tracker::getInstance().getCameraCalibration();
for (int h = 2; h for (int j = 1; j pixelPointMarker = CGPointMake(-15.0 + 6.1 * h, -15.0 + 5.9 * j);
QCAR::Vec2F cameraPoint = QCAR::Tool::projectPoint(cameraCalibration, trackable->getPose(), QCAR::Vec3F(pixelPointMarker.x, pixelPointMarker.y, 0));
glReadPixels(cameraPoint.data[0" />, cameraPoint.data[1" />, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelColor);
NSLog(@"pixelColor: %d, %d, %d", (int) pixelColor[0" />, (int) pixelColor[1" />, (int) pixelColor[2" />);
}
}
[/CODE" />
h and j are numbers between 0 and 5 because I have a matrix of 5x5 circles.
If you could try to see what's happening, here is my image (in PNG because imageshack doesn't allow PDF). This is the Frame Marker with id = 1 from the sample FrameMarkers.

[IMG" />http://img207.imageshack.us/img207/9087/markerpng.png[/IMG" />

PS: I'm not rendering anything on top.

Re: Objects detection inside markers

January 5, 2012 - 4:05pm #10

You should be able to use the camera point returned by the projectPoint method directly.

You haven't rendered anything on top of the target, have you? Note that glReadPixels will get you the final color value, so if there is a purple augmentation on top of the marker it will pull out that color.

The following worked for me with the basic FrameMarkers sample:

// Get the trackable
const QCAR::Trackable* trackable = state.getActiveTrackable(i);
QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

const QCAR::CameraCalibration& cameraCalibration = QCAR::Tracker::getInstance().getCameraCalibration();
QCAR::Vec2F cameraPoint = QCAR::Tool::projectPoint(cameraCalibration, trackable->getPose(), QCAR::Vec3F(0, 0, 0));
NSLog(@"cameraPoint: %f, %f", cameraPoint.data[0], cameraPoint.data[1]);
unsigned char pixelColor[4];
glReadPixels(cameraPoint.data[0], cameraPoint.data[1], 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelColor);
NSLog(@"pixelColor: %d, %d, %d, %d", (int) pixelColor[0], (int) pixelColor[1], (int) pixelColor[2], (int) pixelColor[3]);

- Kim

Re: Objects detection inside markers

January 5, 2012 - 4:52am #9

Yes, this is what I want. So, how do I tell the glReadPixels function that the pixel Point is a camera point and not a screen point ? Do I have to do some projection or do I have to pass an argument to tell the function that I am passing a Camera point ... or something else ?

Because when I directly pass the point coord which are the coord on the camera view, the result is wrong. The circles RGBA colors are equal ... and the color is purple. Which is weird because I have a gray page with black and white circles.

Re: Objects detection inside markers

January 4, 2012 - 7:20pm #8

I saw that you were asking about the cameraPointToScreenPoint function. Note that you actually want to use the camera point (not the screen point) for the glReadPixels function. The camera image is drawn to a glViewport that is larger than the screen, to accommodate the different aspect ratio of the camera.

- Kim

Re: Objects detection inside markers

January 4, 2012 - 3:06am #7

Hi,

I come back here because I've been able to create my marker with my circles inside.
The detection is working:
- I have the exact position of all the circles (I've drawn GL Rectangles inside to be sure).
- I have the screen position of all the circles (I've added a UIImageView over)

but after removing all the elements over my circles to use glReadPixels, it gives me weird results. The pixelColor is varying a lot and is most of the time wrong. It can jump from RGB(30, 30, 30) to RGB(200,200,200) ... which is not good for detection.

Here is the line where I use glReadPixels :
glReadPixels(pixelPoint.x, pixelPoint.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelColor);
where pixelPoint is good and my Marker is printed out on a paper.

Do any of you know why ? Or could help me with another idea ?

Re: Objects detection inside markers

December 23, 2011 - 7:01pm #6

No, QCAR provides the entire camera bitmap, but not a subset for the portion that is contained inside a marker.

It might be simplest to use glReadPixels here. Use the Tool:: projectPoint method to get the coordinates of a point on the marker in camera space (e.g. 0, 0, 0 for the center of the marker). Then use the glReadPixels method to get the color at that point. This is assuming you haven't rendered anything on top of the camera image yet.

- Kim

Re: Objects detection inside markers

December 23, 2011 - 1:47am #5

Hello ppreuss,

Thank you for taking the time to answer me.
Unfortunately, I can't but anything in my circles ... I simplified the scene to post an understandable problem.

Do QCAR provide the image bitmap part inside the marker so I can do some image processing only on this part ? It's going to take less time to analyze only a part of the image rather than the entire image.

I'm taking a look at the samples anyway.

Thanks

Re: Objects detection inside markers

December 22, 2011 - 11:01am #4

Hello DaProd,

QCAR detects patterns so solid color circles will not make good targets. You can put the circle in a Frame Marker, or put a Frame Marker in the circle. Or you can put a distinct pattern(an ImageTarget) inside each circle.

It depends on if you want to detect between each of the 9 circles or you just want to know if the circle is part of group 1(black) or group 2(white). If you need to detect each individually then you need a frame marker for each circle (or a different pattern). Otherwise you just need two, on for all the black circles and one for all the white circles.

Take a look at the FrameMarker sample application for an example of using them. Frame Markers can be put around any image. Alternatively they can be put inside something, like your circle.

Take a look at the ImageTargets sample application to see an example of using ImageTargets. You could then design your own ImageTargets and put them inside your circles to provide detection.

Thank you,

-Peter

Re: Objects detection inside markers

December 22, 2011 - 6:16am #3

I wanted to put all the circles within a marker to be able to detect the circles all at once, then check the color.
Is there a way to output only the image part which is inside the marker ? And then make some image processing on this sub image.

Re: Objects detection inside markers

December 22, 2011 - 4:07am #2

QCAR detects features within an image.
Therefore I would not think it possible to detect individual circles within an image especially if their colours are block black and white.

I guess if you wanted to detect the circles all at once and they don't change their position relative to each other then it would be possible so long as the background was feature rich.

Hope that answers your question,
Rob.

Log in or register to post comments