需要紧急帮助的线程:这里的目标是separtemask将采取每个图像和分开不同的轮廓和图像中的每个轮廓它将调用handleobject线程。所以每个for循环都会调用handeobject线程。但是,对象索引变量需要在每个线程中传递。但是只传递objectndex的最后一个值,这是由于speratemask函数循环并且取消了obj.objindx的值,并且只有传递给所有线程的obj.objindx的最后一个值是 。无论如何都要通过handleobject中的每个objectindex 值。如果我们取消注释pthread_join(tid [objectIndex],NULL),代码运行良好;但它不会给一个parralel程序pthread并行处理
void separateMask(IplImage *maskImg)
{
for(r = contours; r != NULL; r = r->h_next)
{
cvSet(objectMaskImg, cvScalarAll(0), NULL);
CvScalar externalColor = cvScalarAll(0xff);
CvScalar holeColor = cvScalarAll(0x00);
int maxLevel = -1;
int thinkness = CV_FILLED;
int lineType = 8; /* 8-connected */
cvDrawContours(objectMaskImg, r, externalColor, holeColor, maxLevel, thinkness,lineType, cvPoint(0,0));;
obj.objectMaskImg1[objectIndex]=(IplImage *) malloc(sizeof(IplImage));
obj.objectMaskImg1[objectIndex]=objectMaskImg;
obj.objindx=objectIndex;
obj.intensityOut1=intensityOut;
obj.tasOut1=tasOut;
pthread_create(&tid[objectIndex],NULL,handleObject,(void *)&obj);
//pthread_join(tid[objectIndex],NULL);
printf("objectindx %d\n",obj.objindx);
objectIndex++;
}
// cvReleaseImage(&objectMaskImg);
//cvReleaseMemStorage(&storage);
printf("Exitng Separatemask\n");
}
void* handleObject(void *arg)
{
int i, j;
handle *hndl;
hndl=(handle *) malloc(sizeof(handle));
hndl=(handle*)arg;
pthread_mutex_t lock=PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&lock);
IplImage *pImg;
float statistics_ratio[3][9];
pthread_t tid3;
tas3 tas2;
pImg = cvLoadImage("image.tif", CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);
if(pImg == NULL)
{
fprintf(stderr, "Fail to load image %s\n", "tiff file");
return ;
}
tas2.pImg1=pImg;
printf("tst%d\n",hndl->objindx);
tas2.x=hndl->objindx;
tas2.objectMaskImg1=hndl->objectMaskImg1[tas2.x];
tas2.statistics_ratio[3][9]=statistics_ratio[3][9];
double mean = average_intensity(pImg, tas2.objectMaskImg1);
int total = total_white(pImg, tas2.objectMaskImg1);
pthread_mutex_unlock(&lock);
printf("Exiting handle object thread_id %d\n\n", pthread_self());
}
我有一个额外的问题。我附加的代码只能识别未标记的轮廓,只对1和零标记的蒙版执行。我的输入蒙版图像实际上标记为每个轮廓的1,2,3,4 ....例如,第一个轮廓标记为1,第二个轮廓标记为2,所有轮廓仅为1。如何修改我的代码,以便我可以根据标记的图像分别分离每个轮廓。示例contour1是一个单独的图像,contour2是另一个单独的图像。 – user1373805 2012-07-16 21:38:19