int ColorDefinition(int& color, const MinImg* preprocessed_image, const EngineSettings& set) { /* DECLARE_GUARDED_MINIMG(green); PROPAGATE_ERROR(CloneDimensionedMinImagePrototype( &green, preprocessed_image, 1)); int src_channels1[1] = {1}; int dst_channels1[1] = {0}; PROPAGATE_ERROR(CopyMinImageChannels( &green, preprocessed_image, dst_channels1, src_channels1, 1)); int hist[256]; ::memset(hist, 0, 256 * sizeof(*hist)); for (int y = 0; y < green.height; y++) { uint8_t *pLine = green.pScan0 + y * green.stride; for (int x = 0; x < green.width; x++) { hist[pLine[x]]++; } } int threshold = green.width * green.height / 2 + 1; int cnt = 0; int median = 0; for (; median < 256 && cnt < threshold; ++median) { cnt += hist[median]; } if (median < set.median_treshold) color = 0; // red else color = 1; // yellow */ DECLARE_GUARDED_MINIMG(green); PROPAGATE_ERROR(CloneDimensionedMinImagePrototype( &green, preprocessed_image, 1)); int gr_src_channels[1] = {1}; int gr_dst_channels[1] = {0}; PROPAGATE_ERROR(CopyMinImageChannels( &green, preprocessed_image, gr_dst_channels, gr_src_channels, 1)); DECLARE_GUARDED_MINIMG(red); PROPAGATE_ERROR(CloneDimensionedMinImagePrototype( &red, preprocessed_image, 1)); int red_src_channels[1] = {0}; if (preprocessed_image->channels == 4) { // for IPhone BGRA pictures red_src_channels[0] = 2; } int red_dst_channels[1] = {0}; PROPAGATE_ERROR(CopyMinImageChannels( &red, preprocessed_image, red_dst_channels, red_src_channels, 1)); DECLARE_GUARDED_MINIMG(red_green_diff); PROPAGATE_ERROR(CloneMinImagePrototype(&red_green_diff, &red)); PROPAGATE_ERROR(MergeImage(&red_green_diff, &red, &green, BIOP_DIF)); int hist[256]; ::memset(hist, 0, 256 * sizeof(*hist)); static const uint8_t REFACTOR_ME_T = 127; int pixel_count = 0; int x_from = red_green_diff.width / 4; int y_from = red_green_diff.height / 4; for (int y = y_from; y < red_green_diff.height - y_from; y++) { uint8_t *pLine = red_green_diff.pScan0 + y * red_green_diff.stride; uint8_t *pRedLine = red.pScan0 + y * red.stride; for (int x = x_from; x < red_green_diff.width - x_from; x++) { if (pRedLine[x] > REFACTOR_ME_T) { hist[pLine[x]]++; pixel_count++; } } } int threshold = pixel_count / 2 + 1; int cnt = 0; int median = 0; for (; median < 256 && cnt < threshold; ++median) { cnt += hist[median]; } double average = 0.0; for (int i = 0; i < 256; ++i) { average += 1.0 * i * hist[i]; } average /= pixel_count; ////////////// DECLARE_GUARDED_MINIMG(scaled_image); PROPAGATE_ERROR(CloneResizedMinImagePrototype(&scaled_image, &red_green_diff, 1, 1)); PROPAGATE_ERROR(ScaleImage(&scaled_image, &red_green_diff, QO_PIXEL)); uint8_t *pix = scaled_image.pScan0; /* int k = (int)(average + 0.5); ::fprintf(stderr, "%d", k); ////////////*/ if (pix[0] > set.median_treshold) color = 0; // red else color = 1; // yellow return NO_ERRORS; }