@@ -80,7 +80,6 @@ public RDT(Context context, String rdtName) {
80
80
JSONObject obj = new JSONObject (new String (buffer , "UTF-8" )).getJSONObject (rdtName );
81
81
refImageID = context .getResources ().getIdentifier (obj .getString ("REF_IMG" ),
82
82
"drawable" , context .getPackageName ());
83
- refImg = new Mat ();
84
83
Bitmap bitmap = BitmapFactory .decodeResource (context .getResources (), refImageID );
85
84
init (obj , bitmap );
86
85
} catch (Exception ex ) {
@@ -98,6 +97,7 @@ private Bitmap convertByteArrayToBitmap(final byte[] src) {
98
97
99
98
private void init (JSONObject obj , Bitmap bitmap ) throws JSONException {
100
99
// Load the template image
100
+ refImg = new Mat ();
101
101
Utils .bitmapToMat (bitmap , refImg );
102
102
103
103
if (refImg .height () > refImg .width ()) {
@@ -122,10 +122,10 @@ private void init(JSONObject obj, Bitmap bitmap) throws JSONException {
122
122
// Pull data related to the result window
123
123
topLinePosition = rotated ? obj .getJSONArray ("TOP_LINE_POSITION" ).getDouble (1 ) - resultWindowRect .x : obj .getJSONArray ("TOP_LINE_POSITION" ).getDouble (0 ) - resultWindowRect .x ;
124
124
middleLinePosition = rotated ? obj .getJSONArray ("MIDDLE_LINE_POSITION" ).getDouble (1 ) - resultWindowRect .x : obj .getJSONArray ("MIDDLE_LINE_POSITION" ).getDouble (0 ) - resultWindowRect .x ;
125
- bottomLinePosition = rotated ? obj . getJSONArray ( "BOTTOM_LINE_POSITION" ). getDouble ( 1 ) - resultWindowRect . x : obj . getJSONArray ( "BOTTOM_LINE_POSITION" ). getDouble ( 0 ) - resultWindowRect . x ;
125
+ bottomLinePosition = getBottomLinePosition ( obj , rotated ) ;
126
126
topLineName = obj .getString ("TOP_LINE_NAME" );
127
127
middleLineName = obj .getString ("MIDDLE_LINE_NAME" );
128
- bottomLineName = obj .getString ("BOTTOM_LINE_NAME" );
128
+ bottomLineName = obj .optString ("BOTTOM_LINE_NAME" );
129
129
lineIntensity = obj .getInt ("LINE_INTENSITY" );
130
130
lineSearchWidth = obj .has ("LINE_SEARCH_WIDTH" ) ? obj .getInt ("LINE_SEARCH_WIDTH" ) :
131
131
Math .max ((int )((middleLinePosition -topLinePosition )/2.0 ),(int )((bottomLinePosition -middleLinePosition )/2.0 ));
@@ -174,4 +174,10 @@ private void init(JSONObject obj, Bitmap bitmap) throws JSONException {
174
174
matcher = BFMatcher .create (BFMatcher .BRUTEFORCE , false );
175
175
detector .detectAndCompute (refImg , new Mat (), refKeypoints , refDescriptor );
176
176
}
177
+
178
+ private double getBottomLinePosition (JSONObject rdtConfig , boolean rotated ) throws JSONException {
179
+ return rdtConfig .optJSONArray ("BOTTOM_LINE_POSITION" ) == null ? 0
180
+ : rotated ? rdtConfig .getJSONArray ("BOTTOM_LINE_POSITION" ).getDouble (1 ) - resultWindowRect .x
181
+ : rdtConfig .getJSONArray ("BOTTOM_LINE_POSITION" ).getDouble (0 ) - resultWindowRect .x ;
182
+ }
177
183
}
0 commit comments