GdkPixbuf* find_objects_dft (ObjectsMap *map) { int obj_count; IplImage *res_ipl; IplImage *f_result; GdkPixbuf *res_pbuf; int obj_width, obj_height; int map_width, map_height; double min, max; CvPoint min_pnt, max_pnt; g_assert(map->map != NULL && map->objects != NULL && map->n_of_objects != 0); map_width = map->map->width; map_height = map->map->height; res_ipl = cvCreateImage(cvGetSize(map->map), map->map->depth, N_CHANNELS_RGB); cvCvtColor(map->map, res_ipl, CV_GRAY2BGR); obj_count = map->n_of_objects; for (int i = 0; i < obj_count; ++i) { obj_width = map->objects[i]->width; obj_height = map->objects[i]->height; f_result = get_convolution(map->map, map->objects[i]); cvMinMaxLoc(f_result, &min, &max, &min_pnt, &max_pnt, NULL); place_rectangle_with_position(res_ipl, &max_pnt, obj_width, obj_height, POS_DOWN_RIGHT); cvReleaseImage(&f_result); } res_pbuf = ipl2pixbuf(res_ipl); cvReleaseImage(&res_ipl); return res_pbuf; }
static void blur_pixels(double *cmatrix, int cmatrix_length, float *input, float *output, int pixels, int components) { if(cmatrix_length > pixels) { for(int pixel = 0; pixel < pixels; pixel++) { double scale = 0; for(int j = 0; j < pixels; j++) { if((j + cmatrix_length / 2 - pixel >= 0) && (j + cmatrix_length / 2 - pixel < cmatrix_length)) { scale += cmatrix[j + cmatrix_length / 2 - pixel]; } } for(int i = 0; i < components; i++) { double sum = 0; for(int j = 0; j < pixels; j++) { if((j >= pixel - cmatrix_length / 2) && (j <= pixel + cmatrix_length / 2)) { sum += input[j * components + i] * cmatrix[i]; } } output[pixel * components + i] = sum / scale; } } } else { int cmatrix_middle = cmatrix_length / 2; int pixel; for(pixel = 0; pixel < cmatrix_middle; pixel++) { double scale = 0; for(int j = cmatrix_middle - pixel; j < cmatrix_length;j++) { scale += cmatrix[j]; } for(int i = 0; i < components; i++) { double sum = 0; for(int j = cmatrix_middle - pixel; j < cmatrix_length; j++) { sum += input[(pixel + j - cmatrix_middle) * components + i] * cmatrix[j]; } output[pixel * components + i] = sum / scale; } } float *output_ptr = output + pixel * components; for( ; pixel < pixels - cmatrix_middle; pixel++) { float *input_ptr = input + (pixel - cmatrix_middle) * components; for(int i = 0; i < components; i++) { double sum = 0; float *input_ptr2 = input_ptr; for(int j = cmatrix_length; j > 0; j--) { sum += get_convolution(cmatrix, *input_ptr2, cmatrix_length - j); input_ptr2 += components; } input_ptr++; *output_ptr++ = sum; } } for( ; pixel < pixels; pixel++) { double scale = 0; for(int j = 0; j < pixels - pixel + cmatrix_middle; j++) { scale += cmatrix[j]; } for(int i = 0; i < components; i++) { double sum = 0; for(int j = 0; j < pixels - pixel + cmatrix_middle; j++) { sum += input[(pixel + j - cmatrix_middle) * components + i] * cmatrix[j]; } output[pixel * components + i] = sum / scale; } } } }