| | |
| | | import android.widget.TextView; |
| | | import android.widget.Toast; |
| | | |
| | | |
| | | import com.dayu.recharge.R; |
| | | import com.dayu.recharge.view.ViewfinderView; |
| | | import com.yunmai.cc.idcard.controler.CameraManager; |
| | |
| | | import com.yunmai.cc.idcard.controler.OcrManager; |
| | | import com.yunmai.cc.idcard.vo.IdCardInfoNew; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | |
| | | |
| | | /** |
| | | * 视频识别类 |
| | | * |
| | | * @author fangcm 2013-03-18 |
| | | * |
| | | */ |
| | | |
| | | public class CameraActivity extends BaseActivity implements SurfaceHolder.Callback { |
| | | public class CameraActivity extends Activity implements SurfaceHolder.Callback { |
| | | |
| | | private final String TAG = "cc_idcard"; |
| | | |
| | |
| | | private Button btnFlash, btnCancel; |
| | | private ImageView imgTips; |
| | | private ImageView iv, ivHead; |
| | | private int typeFront = 1;// 0不区分 ,1正面,2背面 |
| | | private int typeFront = 0;// 0不区分 ,1正面,2背面 |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | |
| | | super.handleMessage(msg); |
| | | switch (msg.what) { |
| | | case OcrConstant.TAKE_PREVIEW_DATA_OK: |
| | | |
| | | Log.d("yxl", "TAKE_PREVIEW_DATA_OK"); |
| | | if (ocrManager == null) { |
| | | ocrManager = new OcrManager(mHandler, CameraActivity.this); |
| | | try { |
| | |
| | | } |
| | | break; |
| | | case OcrConstant.RECOGN_OK: |
| | | Log.d("yxl", "RECOGN_OK"); |
| | | mHandler.removeMessages(OcrConstant.TAKE_PREVIEW_DATA_OK); |
| | | mHandler.removeMessages(OcrConstant.START_AUTOFOCUS); |
| | | // String imgPath = "/sdcard/aidtest.jpg"; |
| | | // String headPath = "/sdcard/aidheadtest.jpg"; |
| | | |
| | | byte[] headPath = new byte[2048 * 1024 * 3]; |
| | | byte[] imgPath = new byte[2048 * 1024 * 3]; |
| | | byte[] headPath = new byte[2048 * 1024 * 2]; |
| | | byte[] imgPath = new byte[2048 * 1024 * 2]; |
| | | int[] headRect = new int[8]; |
| | | int[] imgRect = new int[8]; |
| | | |
| | | IdCardInfoNew idCardInfo = ocrManager.getResultToByte(imgPath, imgRect, headPath, headRect); |
| | | try { |
| | | String OCRResult = new String(idCardInfo.getCharInfo(), "gbk"); |
| | | Intent intent = new Intent(); |
| | | intent.putExtra("OCRResult", OCRResult); |
| | | setResult(RESULT_OK, intent); |
| | | } catch (UnsupportedEncodingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | // IdCardInfo idCardInfo = ocrManager.getResult(imgPath, headPath); |
| | | Intent data2 = new Intent(); |
| | | data2.putExtra("idcardinfo", idCardInfo); |
| | | setResult(200, data2); |
| | | |
| | | // AppDemo.setResult(idCardInfo); |
| | | // Intent data2 = new Intent(); |
| | | // data2.putExtra("idcardinfo", idCardInfo); |
| | | // setResult(200, data2); |
| | | finish(); |
| | | |
| | | break; |
| | | case OcrConstant.REPEAT_AUTOFOCUS: |
| | | Log.d("yxl", "REPEAT_AUTOFOCUS"); |
| | | |
| | | cameraManager.autoFoucs(); |
| | | mHandler.sendEmptyMessageDelayed(OcrConstant.REPEAT_AUTOFOCUS, 2000); |
| | | break; |
| | | case OcrConstant.RECOGN_EG_TIME_OUT: |
| | | Log.d("yxl", "RECOGN_EG_TIME_OUT"); |
| | | Toast.makeText(getBaseContext(), "引擎过期,请尽快更新!", Toast.LENGTH_LONG).show(); |
| | | finish(); |
| | | break; |
| | | case OcrConstant.RECOGN_EG_LICENSE: |
| | | Log.d("yxl", "RECOGN_EG_LICENSE"); |
| | | |
| | | int ret = -1; |
| | | if (msg.obj != null) { |
| | | ret = (Integer) msg.obj; |
| | |
| | | finish(); |
| | | break; |
| | | case OcrConstant.RECOGN_EG_INIT_ERROR: |
| | | Log.d("yxl", "RECOGN_EG_INIT_ERROR"); |
| | | |
| | | Toast.makeText(getBaseContext(), "引擎初始化失败!", Toast.LENGTH_LONG).show(); |
| | | finish(); |
| | | break; |
| | | case OcrConstant.START_AUTOFOCUS: |
| | | Log.d("yxl", "START_AUTOFOCUS"); |
| | | |
| | | if (autoFoucs) { |
| | | cameraManager.autoFoucs(); |
| | | autoFoucs = false; |
| | |
| | | } |
| | | break; |
| | | case OcrConstant.RECOGN_LINE_IN_RECT: |
| | | Log.d("yxl", "RECOGN_LINE_IN_RECT"); |
| | | |
| | | int restult = (Integer) msg.obj; |
| | | finderView.setLineRect(restult); |
| | | break; |
| | | case OcrConstant.RECOGN_TIPS: |
| | | Log.d("yxl", "RECOGN_TIPS"); |
| | | int tips = (Integer) msg.obj; |
| | | switch (tips) { |
| | | case 1000: |
| | |
| | | |
| | | break; |
| | | default: |
| | | Log.d("yxl", "default"); |
| | | cameraManager.initDisplay(); |
| | | mHandler.sendEmptyMessageDelayed(OcrConstant.START_AUTOFOCUS, 500); |
| | | Toast.makeText(getBaseContext(), "<>" + msg.what, Toast.LENGTH_SHORT).show(); |