[Phission-cvs] phission/filter/video/src phblob.c,1.19,1.20
Brought to you by:
pthoren
From: Philip T. <pt...@us...> - 2007-06-28 23:19:47
|
Update of /cvsroot/phission/phission/filter/video/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11850/filter/video/src Modified Files: phblob.c Log Message: Cleaned up the API a bit; Moved all the draw_rects and color_lines function parameters into the args structure; This will reduce the stack overhead, but it's not a huge performance increase, just cleaner. Added support for Region Of Interest coloring/rectangle drawing for blobs. This allows the code to work in conjunction with an interface where one would only want to highlight an object whose blob center is close to the center of the click. It might not work well for a long or tall object if one doesn't click in center of the object. Added support for a max blob size as another means to remove noise such as that caused by backgrounds that also match the object color thresholds. Added a print_blob function from code that was in phBlobData.cpp Index: phblob.c =================================================================== RCS file: /cvsroot/phission/phission/filter/video/src/phblob.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** phblob.c 8 Jun 2007 21:18:04 -0000 1.19 --- phblob.c 28 Jun 2007 23:16:14 -0000 1.20 *************** *** 1275,1287 **** } /* ---------------------------------------------------------------------- */ ! int phblob_draw_blob_rects( uint8_t *imgptr, ! uint32_t width, ! uint32_t height, ! uint32_t format, ! const phColor *color, ! phblob_data *data, ! uint32_t index, ! uint32_t min_size, ! uint32_t flag ) { phFUNCTION("phblob_draw_blob_rects") --- 1275,1280 ---- } /* ---------------------------------------------------------------------- */ ! int phblob_draw_blob_rects( phblob_args *args, ! phblob_data *data ) { phFUNCTION("phblob_draw_blob_rects") *************** *** 1292,1319 **** phblob *blobs = data->blobs; uint32_t nblobs = data->nblobs; ! if (color == NULL) flag |= phBLOB_COLOR_BLACK; ! if ((flag & phBLOB_COLOR_BLACK) == phBLOB_COLOR_BLACK) { ! if ((format == (uint32_t)phImageYUV9) || ! (format == (uint32_t)phImageNOFORMAT)) { phCHECK_RC(-1,NULL,"Unsupported Image Format"); } ! outcolor = phColor_new(phImageFormatToColorType(format)); } else { ! outcolor = *color; } ! surface.p = imgptr; ! surface.w = width; ! surface.h = height; ! surface.f = format; ! surface.d = phImageFormatToDepth(format); ! ! if (((flag & phBLOB_DRAW_ALL) == phBLOB_DRAW_ALL) && (nblobs > 0)) { --- 1285,1335 ---- phblob *blobs = data->blobs; uint32_t nblobs = data->nblobs; + uint32_t near = 1; + uint32_t x1 = 0; + uint32_t x2 = 0; + uint32_t y1 = 0; + uint32_t y2 = 0; + uint32_t flags = 0; + uint32_t min_size = 0; + uint32_t max_size = 0; ! if ((args == NULL) || (data == NULL)) return phFAIL; ! ! flags = args->flags; ! if (args->outcolor == NULL) flags |= phBLOB_COLOR_BLACK; ! ! if ((flags & phBLOB_COLOR_BLACK) == phBLOB_COLOR_BLACK) { ! if ((args->format == (uint32_t)phImageYUV9) || ! (args->format == (uint32_t)phImageNOFORMAT)) { phCHECK_RC(-1,NULL,"Unsupported Image Format"); } ! outcolor = phColor_new(phImageFormatToColorType(args->format)); } else { ! outcolor = *(args->outcolor); } ! blobs = data->blobs; ! nblobs = data->nblobs; ! ! surface.p = *(args->imgptr); ! surface.w = args->width; ! surface.h = args->height; ! surface.f = args->format; ! surface.d = phImageFormatToDepth(args->format); ! ! x1 = args->roi.x1; ! x2 = args->roi.x2; ! y1 = args->roi.y1; ! y2 = args->roi.y2; ! ! min_size = args->minsize; ! max_size = args->maxsize; ! ! if (((flags & phBLOB_DRAW_ALL) == phBLOB_DRAW_ALL) && (nblobs > 0)) { *************** *** 1323,1335 **** while (current_blob != NULL) { ! if (current_blob->mass > min_size) { ! ph_draw_hollow_rect(&surface, ! outcolor, ! 0, ! current_blob->x1, ! current_blob->y1, ! current_blob->x2, ! current_blob->y2 ); } --- 1339,1371 ---- while (current_blob != NULL) { ! if ((current_blob->mass >= min_size) && ! (current_blob->mass <= max_size)) { ! /* Check to see if the blob is within a given region */ ! if ((flags & phBLOB_DRAW_ROI) == phBLOB_DRAW_ROI) ! { ! if ((current_blob->cx >= x1) && ! (current_blob->cx <= x2) && ! (current_blob->cy >= y1) && ! (current_blob->cy <= y2)) ! { ! near = 1; ! } ! else ! { ! near = 0; ! } ! } ! ! if (near) ! { ! ph_draw_hollow_rect(&surface, ! outcolor, ! 0, ! current_blob->x1, ! current_blob->y1, ! current_blob->x2, ! current_blob->y2 ); ! } } *************** *** 1337,1345 **** } } ! if ((flag & phBLOB_DRAW_INDEX) == phBLOB_DRAW_INDEX) { ! if (index < nblobs) { ! current_blob = (&(blobs[index])); ph_draw_hollow_rect(&surface, --- 1373,1381 ---- } } ! if ((flags & phBLOB_DRAW_INDEX) == phBLOB_DRAW_INDEX) { ! if (args->index < nblobs) { ! current_blob = (&(blobs[args->index])); ph_draw_hollow_rect(&surface, *************** *** 1359,1374 **** /* ---------------------------------------------------------------------- */ ! int phblob_color_lines(uint8_t *imgptr, ! uint32_t width, ! uint32_t height, ! uint32_t format, ! const phColor *color, ! phblob_data *data, ! uint32_t blob_min_size, ! uint32_t index, /* TODO */ ! uint32_t flag ) { phFUNCTION("phblob_color_lines") uint32_t i = 0; uint32_t j = 0; --- 1395,1404 ---- /* ---------------------------------------------------------------------- */ ! int phblob_color_lines(phblob_args *args, ! phblob_data *data ) { phFUNCTION("phblob_color_lines") + uint32_t near = 1; uint32_t i = 0; uint32_t j = 0; *************** *** 1381,1384 **** --- 1411,1423 ---- phColor outcolor; + uint32_t x1 = args->roi.x1; + uint32_t x2 = args->roi.x2; + uint32_t y1 = args->roi.y1; + uint32_t y2 = args->roi.y2; + uint32_t flags = args->flags; + uint32_t minsize = args->minsize; + uint32_t maxsize = args->maxsize; + uint8_t *imgptr = *(args->imgptr); + uint32_t nblobs = data->nblobs; phblob *blobs = data->blobs; *************** *** 1390,1415 **** uint8_t *ptr = NULL; //uint32_t color_line = 0; ! if (color == NULL) flag |= phBLOB_COLOR_BLACK; /* set black if it's requested */ ! if ((flag & phBLOB_COLOR_BLACK) == phBLOB_COLOR_BLACK) { ! if ((format == (uint32_t)phImageYUV9) || ! (format == (uint32_t)phImageNOFORMAT)) { phCHECK_RC(-1,NULL,"Unsupported Image Format"); } ! outcolor = phColor_new(phImageFormatToColorType(format)); } else { ! outcolor = *color; } - ! if ((format == (uint32_t)phImageYUV9) || ! (format == (uint32_t)phImageNOFORMAT)) { phCHECK_RC(-1,NULL,"Unsupported Image Format"); --- 1429,1454 ---- uint8_t *ptr = NULL; + //uint32_t color_line = 0; ! if (args->outcolor == NULL) flags |= phBLOB_COLOR_BLACK; /* set black if it's requested */ ! if ((flags & phBLOB_COLOR_BLACK) == phBLOB_COLOR_BLACK) { ! if ((args->format == (uint32_t)phImageYUV9) || ! (args->format == (uint32_t)phImageNOFORMAT)) { phCHECK_RC(-1,NULL,"Unsupported Image Format"); } ! outcolor = phColor_new(phImageFormatToColorType(args->format)); } else { ! outcolor = *(args->outcolor); } ! if ((args->format == (uint32_t)phImageYUV9) || ! (args->format == (uint32_t)phImageNOFORMAT)) { phCHECK_RC(-1,NULL,"Unsupported Image Format"); *************** *** 1418,1434 **** else { ! depth = phImageFormatToDepth(format); } ! if ((flag & phBLOB_CLEAR_IMG) == phBLOB_CLEAR_IMG) { ! phMemset(imgptr,0,width*height*depth); } ! if (blob_min_size > 0) { for (k = 0; (k < nblobs) && (blobs); k++ ) { ! if (blobs[k].mass > blob_min_size) blob_count++; } } --- 1457,1481 ---- else { ! depth = phImageFormatToDepth(args->format); } ! /* ! * phPROGRESS("flags:%08x\n",flags); ! */ ! if ((flags & phBLOB_CLEAR_IMG) == phBLOB_CLEAR_IMG) { ! phMemset(imgptr,0,args->width*args->height*depth); } ! /* Only figure out the blob count if the min and max value settings are not ! * at their limit values; i.e. they have been set by the user */ ! if ((minsize > 0) || (maxsize > 0)) { for (k = 0; (k < nblobs) && (blobs); k++ ) { ! if ((blobs[k].mass >= minsize) && (blobs[k].mass <= maxsize)) ! { ! blob_count++; ! } } } *************** *** 1443,1447 **** for (i = 0; i < nrows; i++ ) { ! irow = i * width; /* Get the index to the first line segment in the row */ --- 1490,1494 ---- for (i = 0; i < nrows; i++ ) { ! irow = i * args->width; /* Get the index to the first line segment in the row */ *************** *** 1460,1469 **** #endif blob_index = current_segment->blob_index; ! /* TODO: make coloring all the lines an option */ ! if ((blob_index >= 0) && (((uint32_t)blob_index) < nblobs) && ! ((blob_min_size == 0) || ! (blobs[blob_index].mass >= blob_min_size))) { if (data->blob_method == phBLOB_NEIGHBOR) { --- 1507,1545 ---- #endif blob_index = current_segment->blob_index; ! ! if ((flags & phBLOB_DRAW_ROI) == phBLOB_DRAW_ROI) ! { ! if ((blobs[blob_index].cx >= x1) && ! (blobs[blob_index].cx <= x2) && ! (blobs[blob_index].cy >= y1) && ! (blobs[blob_index].cy <= y2)) ! { ! /* ! phPROGRESS("%d >= %d | %d <= %d : %d >= %d | %d <= %d", ! blobs[blob_index].cx, x1, ! blobs[blob_index].cx, x2, ! blobs[blob_index].cy, y1, ! blobs[blob_index].cy, y2 ); ! */ ! near = 1; ! } ! else ! { ! near = 0; ! } ! } ! ! /* TODO: make coloring all the lines an option */ ! if ((near) && ! (blob_index >= 0) && (((uint32_t)blob_index) < nblobs) && ! ((minsize == 0) || ! (blobs[blob_index].mass >= minsize)) && ! ((maxsize == 0) || ! (blobs[blob_index].mass <= maxsize)) ! ) { + + if (data->blob_method == phBLOB_NEIGHBOR) { *************** *** 1864,1867 **** --- 1940,1965 ---- /* ---------------------------------------------------------------------- */ + void print_blob( phblob *blob, int k ) + { + if (blob != NULL) + { + printf("\tk:%4lu blob[%4lu](mass: %6lu, w:%4lu, h:%4lu," + "c(%4lu, %4lu) ul(%4lu, %4lu) lr(%4lu, %4lu))\n", + (long unsigned)k, + (long unsigned)blob->index, + (long unsigned)blob->mass, + (long unsigned)blob->w, + (long unsigned)blob->h, + (long unsigned)blob->cx, + (long unsigned)blob->cy, + (long unsigned)blob->x1, + (long unsigned)blob->y1, + (long unsigned)blob->x2, + (long unsigned)blob->y2 ); + + } + } + + /* ---------------------------------------------------------------------- */ #ifdef __cplusplus } /* extern "C" */ |