Skip to content

Commit

Permalink
Merge pull request card-io#28 from COCUS-NEXT/feature/blur
Browse files Browse the repository at this point in the history
feat: implement blur in DMZ sources
  • Loading branch information
bluk committed May 11, 2016
2 parents 32d1bc1 + 5153832 commit 3291a21
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
20 changes: 19 additions & 1 deletion dmz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "cv/stats.h"
#include "cv/warp.h"
#include "opencv2/core/core_c.h" // needed for IplImage
#include "opencv2/imgproc/imgproc.hpp"

#pragma mark life cycle

Expand Down Expand Up @@ -494,6 +495,23 @@ void dmz_transform_card(dmz_context *dmz, IplImage *sample, dmz_corner_points co
llcv_unwarp(dmz, sample, src_points, dst_rect, *transformed);
}

void dmz_blur_card(IplImage* cardImageRGB, ScannerState* state, int unblur)
{
int blurCount = state->mostRecentUsableHSeg.n_offsets - unblur;
for (int i = 0; i < state->mostRecentUsableHSeg.n_offsets && i < blurCount ; i++) {
int num_x = state->mostRecentUsableHSeg.offsets[i] - 1;
int num_y = state->mostRecentUsableVSeg.y_offset - 1;
int num_w = state->mostRecentUsableHSeg.number_width + 2;
int num_h = kNumberHeight + 2;
if (i < 4) num_h *= 2; // blur smaller four digits below first bucket
cvSetImageROI(cardImageRGB, cvRect(num_x, num_y, num_w, num_h));
cv::Mat blurMat = cv::Mat(cardImageRGB, false);
cv::medianBlur(blurMat, blurMat, 25);
blurMat.release();
}
cvResetImageROI(cardImageRGB);
}

// FOR CYTHON USE ONLY
#if CYTHON_DMZ
void dmz_scharr3_dx_abs(IplImage *src, IplImage *dst) {
Expand Down Expand Up @@ -653,4 +671,4 @@ void dmz_expiry_extract_group(IplImage *card_y,
}
#endif

#endif // COMPILE_DMZ
#endif // COMPILE_DMZ
6 changes: 5 additions & 1 deletion dmz.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//

#include "dmz_olm.h"
#include "scan/scan.h"

#include "opencv2/core/core_c.h" // needed for IplImage

Expand Down Expand Up @@ -92,6 +93,9 @@ bool dmz_detect_edges(IplImage *y_sample, IplImage *cb_sample, IplImage *cr_samp
// to free transformed.
void dmz_transform_card(dmz_context *dmz, IplImage *sample, dmz_corner_points corner_points, FrameOrientation orientation, bool upsample, IplImage **transformed);

// Blurs card number digits on a result image
// the 'unblur' argument defines how many digits not to blur to remain visible.
void dmz_blur_card(IplImage* cardImageRGB, ScannerState* state, int unblur);

// FOR CYTHON USE ONLY
#if CYTHON_DMZ
Expand All @@ -113,4 +117,4 @@ void dmz_expiry_extract_group(IplImage *card_y,
#endif


#endif // DMZ_H
#endif // DMZ_H

0 comments on commit 3291a21

Please sign in to comment.