Hi. This thread thing is confusing me, I just can’t get over it. Here’s my basic goal:
I want my app to be able to load images when I select them with an ofSystemLoadDiaglog(), then use Haar detection to find the faces in the images. I am just trying to learn threading, this is just a simple test I came up with. I have everything working fine, only when I select the image to load, it is supposed to then add it to my new threaded function where it uses opencv to detect the face. When I run the app it works fine until I try to load a new image. I always get EXC_BAD_ACCESS on this line in ofTexture: glGenTextures(1, (GLuint *)&texData.textureID);
Here is my threaded function .cpp file:
#include "haarThread.h"
#include "ofMain.h"
#include <iostream>
haarThread::haarThread()
:ofThread()
{
imgPath = "";
haarImg.setUseTexture(false);
}
void haarThread::setup(string haarFilePath) {
lock();
haarFind.setup(haarFilePath);
unlock();
}
void haarThread::loadImagePath(string filename) {
lock();
imgPath = filename;
unlock();
}
void haarThread::threadedFunction() {
while(true) {
//cout << "my own custom thread!" << endl;
//ofSleepMillis(3000);
haarImg.setUseTexture(false);
haarImg.loadImage(imgPath);
haarFind.findHaarObjects(haarImg);
faceRect = haarFind.blobs[0].boundingRect;
haarImg.crop(faceRect.x, faceRect.y, faceRect.width, faceRect.height);
}
}