This repository has been archived by the owner on Jan 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 376
feature: scan_progress #73
Open
m-schmoock
wants to merge
12
commits into
card-io:master
Choose a base branch
from
COCUSAG:feature/scan_progress
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f510eac
feat: scan_progress variable
m-schmoock 0b9a566
chore: set submodule tracking feature branch
m-schmoock bdca783
chore: added new scan progress states
m-schmoock 2270499
fix: pass scan progress back to java
m-schmoock d0dcb02
feat: scan result
m-schmoock 665c95b
fix: update compare scan_progress
f09caf0
feat: autofocus once after SCAN_PROGRESS_HSEG
m-schmoock 734f258
feat: color based on progress
m-schmoock fdd9ce0
fix: update progress when no card was detected
m-schmoock d91c6ee
chore: set dmz reference for feature/scan_progress
m-schmoock e0b1376
chore: fix code style a tiny bit
m-schmoock da8f0b7
refactor: not apply progress color to the guide
m-schmoock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule card.io-dmz
updated
4 files
+7 −0 | scan/frame.cpp | |
+14 −0 | scan/frame.h | |
+18 −9 | scan/scan.cpp | |
+1 −0 | scan/scan.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ static int dmz_refcount = 0; | |
static ScannerState scannerState; | ||
static bool detectOnly; | ||
static bool flipped; | ||
static bool lastFrameWasUsable; | ||
static bool focusTriggered; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this removed? Is it unused? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, nowhere in it is was used or referenced. I just removed it because I stumbled upon it. I think the iOS part has a variable like this. Maybe it got obsolete somewhere due to refactorization. |
||
static float minFocusScore; | ||
|
||
static struct { | ||
|
@@ -50,6 +50,7 @@ static struct { | |
jfieldID expiry_month; | ||
jfieldID expiry_year; | ||
jfieldID detectedCard; | ||
jfieldID scanProgress; | ||
} detectionInfoId; | ||
|
||
static struct { | ||
|
@@ -135,12 +136,13 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { | |
detectionInfoId.expiry_month = env->GetFieldID(dInfoClass, "expiry_month", "I"); | ||
detectionInfoId.expiry_year = env->GetFieldID(dInfoClass, "expiry_year", "I"); | ||
detectionInfoId.detectedCard = env->GetFieldID(dInfoClass, "detectedCard", "Lio/card/payment/CreditCard;"); | ||
detectionInfoId.scanProgress = env->GetFieldID(dInfoClass, "scanProgress", "I"); | ||
|
||
if (!(detectionInfoId.complete && detectionInfoId.topEdge && detectionInfoId.bottomEdge | ||
&& detectionInfoId.leftEdge && detectionInfoId.rightEdge | ||
&& detectionInfoId.focusScore && detectionInfoId.prediction | ||
&& detectionInfoId.expiry_month && detectionInfoId.expiry_year | ||
&& detectionInfoId.detectedCard | ||
&& detectionInfoId.detectedCard && detectionInfoId.scanProgress | ||
)) { | ||
dmz_error_log("at least one field was not found for DetectionInfo"); | ||
return -1; | ||
|
@@ -159,7 +161,7 @@ JNIEXPORT void JNICALL Java_io_card_payment_CardScanner_nSetup(JNIEnv *env, jobj | |
detectOnly = shouldOnlyDetectCard; | ||
minFocusScore = jMinFocusScore; | ||
flipped = false; | ||
lastFrameWasUsable = false; | ||
focusTriggered = false; | ||
|
||
if (dmz == NULL) { | ||
dmz = dmz_context_create(); | ||
|
@@ -313,7 +315,8 @@ JNIEXPORT void JNICALL Java_io_card_payment_CardScanner_nScanFrame(JNIEnv *env, | |
orientation = dmz_opposite_orientation(orientation); | ||
} | ||
|
||
FrameScanResult result; | ||
FrameScanResult frameResult = {0}; | ||
dmz_edges found_edges = {0}; | ||
|
||
IplImage *image = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 1); | ||
jbyte *jBytes = env->GetByteArrayElements(jb, 0); | ||
|
@@ -322,7 +325,9 @@ JNIEXPORT void JNICALL Java_io_card_payment_CardScanner_nScanFrame(JNIEnv *env, | |
float focusScore = dmz_focus_score(image, false); | ||
env->SetFloatField(dinfo, detectionInfoId.focusScore, focusScore); | ||
dmz_trace_log("focus score: %f", focusScore); | ||
|
||
if (focusScore >= minFocusScore) { | ||
frameResult.scan_progress = SCAN_PROGRESS_FOCUS; | ||
|
||
IplImage *cbcr = cvCreateImageHeader(cvSize(width / 2, height / 2), IPL_DEPTH_8U, 2); | ||
cbcr->imageData = ((char *)jBytes) + width * height; | ||
|
@@ -333,33 +338,38 @@ JNIEXPORT void JNICALL Java_io_card_payment_CardScanner_nScanFrame(JNIEnv *env, | |
|
||
cvReleaseImageHeader(&cbcr); | ||
|
||
dmz_edges found_edges; | ||
dmz_corner_points corner_points; | ||
bool cardDetected = dmz_detect_edges(image, cb, cr, | ||
orientation, | ||
&found_edges, &corner_points | ||
); | ||
|
||
updateEdgeDetectDisplay(env, thiz, dinfo, found_edges); | ||
|
||
if (cardDetected) { | ||
frameResult.scan_progress = SCAN_PROGRESS_EDGES; | ||
IplImage *cardY = NULL; | ||
dmz_transform_card(NULL, image, corner_points, orientation, false, &cardY); | ||
|
||
if (!detectOnly) { | ||
result.focus_score = focusScore; | ||
result.flipped = flipped; | ||
scanner_add_frame_with_expiry(&scannerState, cardY, jScanExpiry, &result); | ||
if (result.usable) { | ||
ScannerResult scanResult; | ||
scanner_result(&scannerState, &scanResult); | ||
frameResult.focus_score = focusScore; | ||
frameResult.flipped = flipped; | ||
scanner_add_frame_with_expiry(&scannerState, cardY, jScanExpiry, &frameResult); | ||
|
||
// trigger focus once when scanprogress reaches certain levels | ||
if(frameResult.scan_progress >= SCAN_PROGRESS_HSEG && !focusTriggered) { | ||
focusTriggered = true; | ||
env->SetFloatField(dinfo, detectionInfoId.focusScore, 0.0f); | ||
dmz_debug_log("forcing re-focus on scan progress"); | ||
} | ||
|
||
if (frameResult.usable) { | ||
ScannerResult scanResult = {0}; | ||
scanner_frame_result(&scannerState, &scanResult, &frameResult); | ||
|
||
if (scanResult.complete) { | ||
setScanCardNumberResult(env, dinfo, &scanResult); | ||
logDinfo(env, dinfo); | ||
} | ||
} | ||
else if (result.upside_down) { | ||
} else if (frameResult.upside_down) { | ||
flipped = !flipped; | ||
} | ||
} | ||
|
@@ -372,6 +382,12 @@ JNIEXPORT void JNICALL Java_io_card_payment_CardScanner_nScanFrame(JNIEnv *env, | |
cvReleaseImage(&cr); | ||
} | ||
|
||
// set scan progress and update edges (on every frame) | ||
env->SetIntField(dinfo, detectionInfoId.scanProgress, frameResult.scan_progress); | ||
// release focus trigger when frame was shit | ||
if (frameResult.scan_progress < SCAN_PROGRESS_VSEG) focusTriggered = false; | ||
updateEdgeDetectDisplay(env, thiz, dinfo, found_edges); | ||
|
||
cvReleaseImageHeader(&image); | ||
env->ReleaseByteArrayElements(jb, jBytes, 0); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spacing is not consistent. Don't put a space before
int
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed by e0b1376