Hey everyone,
I’m currently having an issue with ofPoint’s set method.
I have a class called IRTracker that looks like this:
NOTE: ofpoint_srcPoints and ofpoint_dstPoints are arrays of ofPoint with a length of 4
#include "IRTracker.h"
IRTracker::IRTracker() {
b_cameraSetup = false;
b_videoSetup = false;
f_playerBlobArea = 100.00;
}
void IRTracker::setupCamera(int i_deviceNumber) {
// setup device
ofvidGrab_irFeed.setDeviceID(i_deviceNumber);
// setup video grabber:
ofvidGrab_irFeed.initGrabber(320, 240);
// get the width and height, and allocate color and grayscale images:
i_width = ofvidGrab_irFeed.width;
i_height = ofvidGrab_irFeed.height;
}
void IRTracker::setupCV() {
// setup video grabber:
ofvidGrab_irFeed.initGrabber(320, 240);
// get the width and height, and allocate color and grayscale images:
i_width = ofvidGrab_irFeed.width;
i_height = ofvidGrab_irFeed.height;
ofxCvColor_irColorImage.allocate(i_width, i_height);
ofxCvGray_irGrayImage.allocate(i_width, i_height);
ofxCvGray_irGrayImagePreWarp.allocate(i_width, i_height);
ofxCvGray_videoBgImage.allocate(i_width, i_height);
ofxCvGray_irDiffImage.allocate(i_width, i_height);
// set Default points
ofpoint_srcPoints[0].set(0.0, 0.0, 0.0);
ofpoint_srcPoints[1].set(320.0, 0.0, 0.0);
ofpoint_srcPoints[2].set(320.0, 240.0, 0.0);
ofpoint_srcPoints[3].set(0.0, 240.0, 0.0);
ofpoint_dstPoints[0].set(0.0, 0.0, 0.0);
ofpoint_dstPoints[1].set(320.0, 0.0, 0.0);
ofpoint_dstPoints[2].set(320.0, 240.0, 0.0);
ofpoint_dstPoints[3].set(0.0, 240.0, 0.0);
for(int i=0; i<4; i++)
{
printf("setup src pnts: %d, %d \n", ofpoint_srcPoints[i].x,ofpoint_srcPoints[i].y);
}
}
//process the incoming frame and look for a laser
void IRTracker::processFrame() {
///////////////////////////////////////////////////////////
// Part 1 - get the video data
///////////////////////////////////////////////////////////
bool bLearnBg = false;
int threshold = 196;
int minBlobSize = 25;
int maxBlobSize = 1000;
int nBlobsConsidered = 2;
ofvidGrab_irFeed.update();
if (ofvidGrab_irFeed.isFrameNew()){
ofxCvColor_irColorImage.setFromPixels(ofvidGrab_irFeed.getPixels(), i_width, i_height);
ofxCvGray_irGrayImage = ofxCvColor_irColorImage;
ofxCvGray_irGrayImage.warpIntoMe(ofxCvGray_irGrayImagePreWarp, ofpoint_srcPoints, ofpoint_dstPoints);
if (bLearnBg){
ofxCvGray_videoBgImage = ofxCvGray_irGrayImage;
}
if (ofGetElapsedTimef() < 1.5){
ofxCvGray_videoBgImage = ofxCvGray_irGrayImage;
}
ofxCvGray_irDiffImage.absDiff(ofxCvGray_irGrayImage, ofxCvGray_videoBgImage);
ofxCvGray_irDiffImage.threshold(threshold);
ofxCvContourFind_contourFinder.findContours(ofxCvGray_irDiffImage, minBlobSize, maxBlobSize, nBlobsConsidered, false, true);
}
}
void IRTracker::drawFeed() {
ofxCvGray_irGrayImage.draw(20,20, 320,240);
ofxCvGray_videoBgImage.draw(320+40, 20, 320, 240);
ofxCvGray_irDiffImage.draw(20,240+40);
ofxCvContourFind_contourFinder.draw(20,240+40);
}
int IRTracker::getPlayerBlobX() {
// Assumes a cv has been set up and frame processed
int f_x_pos_returned;
for (int i = 0; i < ofxCvContourFind_contourFinder.nBlobs; i++){
if(ofxCvContourFind_contourFinder.blobs[i].area >= f_playerBlobArea)
{
f_x_pos_returned = ofxCvContourFind_contourFinder.blobs[i].centroid.x;
}
else
{
f_x_pos_returned = 0;
}
}
return ((int) f_x_pos_returned);
}
int IRTracker::getPlayerBlobY() {
// Assumes a cv has been set up and frame processed
int f_y_pos_returned;
for (int i = 0; i < ofxCvContourFind_contourFinder.nBlobs; i++){
if(ofxCvContourFind_contourFinder.blobs[i].area >= f_playerBlobArea)
{
f_y_pos_returned = ofxCvContourFind_contourFinder.blobs[i].centroid.y;
}
else
{
f_y_pos_returned = 0;
}
}
return ((int) f_y_pos_returned);
}
void IRTracker::setSourcePoint(int i_point_adjusting, int i_x, int i_y) {
ofpoint_srcPoints[i_point_adjusting].set((float) i_x, (float) i_y);
printf("Params are: %d, %d \n", i_x, i_y);
printf("Source points after set: %d, %d \n", ofpoint_srcPoints[i_point_adjusting].x, ofpoint_srcPoints[i_point_adjusting].y);
}
My problem lies in the setupCV() method. when i set each point in ofpoint_srcPoints (or in ofpoint_dstPoints for that matter) and then print them out i dont get the values i set them to, but something like this:
setup src pnts: 0, 0
setup src pnts: 0, 1081344000
setup src pnts: 0, 1081344000
setup src pnts: 0, 0
A similar thing happens when I set the source points on a mouse click the value it gets set to is not the x or y of the mouse location.
Has anybody had a situation like this or possible sees something i dont see?