支持识别反色码(#66,#72)
This commit is contained in:
@@ -64,6 +64,7 @@ public class CustomActivity extends AppCompatActivity implements OnCaptureCallba
|
|||||||
mCaptureHelper.vibrate(true)
|
mCaptureHelper.vibrate(true)
|
||||||
.fullScreenScan(true)//全屏扫码
|
.fullScreenScan(true)//全屏扫码
|
||||||
.supportVerticalCode(true)//支持扫垂直条码,建议有此需求时才使用。
|
.supportVerticalCode(true)//支持扫垂直条码,建议有此需求时才使用。
|
||||||
|
.supportLuminanceInvert(true)//是否支持识别反色码(黑白反色的码),增加识别率
|
||||||
.continuousScan(isContinuousScan);
|
.continuousScan(isContinuousScan);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ public class CustomCaptureActivity extends CaptureActivity {
|
|||||||
.frontLightMode(FrontLightMode.AUTO)//设置闪光灯模式
|
.frontLightMode(FrontLightMode.AUTO)//设置闪光灯模式
|
||||||
.tooDarkLux(45f)//设置光线太暗时,自动触发开启闪光灯的照度值
|
.tooDarkLux(45f)//设置光线太暗时,自动触发开启闪光灯的照度值
|
||||||
.brightEnoughLux(100f)//设置光线足够明亮时,自动触发关闭闪光灯的照度值
|
.brightEnoughLux(100f)//设置光线足够明亮时,自动触发关闭闪光灯的照度值
|
||||||
.continuousScan(isContinuousScan);//是否连扫
|
.continuousScan(isContinuousScan)//是否连扫
|
||||||
|
.supportLuminanceInvert(true);//是否支持识别反色码(黑白反色的码),增加识别率
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package com.king.zxing;
|
package com.king.zxing;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -26,7 +26,7 @@ import android.view.View;
|
|||||||
import com.king.zxing.camera.CameraManager;
|
import com.king.zxing.camera.CameraManager;
|
||||||
|
|
||||||
|
|
||||||
public class CaptureActivity extends Activity implements OnCaptureCallback{
|
public class CaptureActivity extends AppCompatActivity implements OnCaptureCallback{
|
||||||
|
|
||||||
public static final String KEY_RESULT = Intents.Scan.RESULT;
|
public static final String KEY_RESULT = Intents.Scan.RESULT;
|
||||||
|
|
||||||
@@ -113,9 +113,10 @@ public class CaptureActivity extends Activity implements OnCaptureCallback{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get {@link CameraManager}
|
* Get {@link CameraManager} use {@link #getCaptureHelper()#getCameraManager()}
|
||||||
* @return {@link #mCaptureHelper#getCameraManager()}
|
* @return {@link #mCaptureHelper#getCameraManager()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public CameraManager getCameraManager(){
|
public CameraManager getCameraManager(){
|
||||||
return mCaptureHelper.getCameraManager();
|
return mCaptureHelper.getCameraManager();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,9 +126,10 @@ public class CaptureFragment extends Fragment implements OnCaptureCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get {@link CameraManager}
|
* Get {@link CameraManager} use {@link #getCaptureHelper()#getCameraManager()}
|
||||||
* @return {@link #mCaptureHelper#getCameraManager()}
|
* @return {@link #mCaptureHelper#getCameraManager()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public CameraManager getCameraManager(){
|
public CameraManager getCameraManager(){
|
||||||
return mCaptureHelper.getCameraManager();
|
return mCaptureHelper.getCameraManager();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ public class CaptureHandler extends Handler implements ResultPointCallback {
|
|||||||
*/
|
*/
|
||||||
private boolean isSupportAutoZoom;
|
private boolean isSupportAutoZoom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private boolean isSupportLuminanceInvert;
|
||||||
|
|
||||||
|
|
||||||
private enum State {
|
private enum State {
|
||||||
PREVIEW,
|
PREVIEW,
|
||||||
@@ -198,4 +203,12 @@ public class CaptureHandler extends Handler implements ResultPointCallback {
|
|||||||
public void setSupportAutoZoom(boolean supportAutoZoom) {
|
public void setSupportAutoZoom(boolean supportAutoZoom) {
|
||||||
isSupportAutoZoom = supportAutoZoom;
|
isSupportAutoZoom = supportAutoZoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSupportLuminanceInvert() {
|
||||||
|
return isSupportLuminanceInvert;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSupportLuminanceInvert(boolean supportLuminanceInvert) {
|
||||||
|
isSupportLuminanceInvert = supportLuminanceInvert;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,11 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
|||||||
*/
|
*/
|
||||||
private boolean isSupportAutoZoom = true;
|
private boolean isSupportAutoZoom = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否支持识别颜色反转色的码,黑白颜色反转,默认不支持
|
||||||
|
*/
|
||||||
|
private boolean isSupportLuminanceInvert = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否支持连扫,默认不支持
|
* 是否支持连扫,默认不支持
|
||||||
*/
|
*/
|
||||||
@@ -333,6 +338,7 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
|||||||
captureHandler.setSupportVerticalCode(isSupportVerticalCode);
|
captureHandler.setSupportVerticalCode(isSupportVerticalCode);
|
||||||
captureHandler.setReturnBitmap(isReturnBitmap);
|
captureHandler.setReturnBitmap(isReturnBitmap);
|
||||||
captureHandler.setSupportAutoZoom(isSupportAutoZoom);
|
captureHandler.setSupportAutoZoom(isSupportAutoZoom);
|
||||||
|
captureHandler.setSupportLuminanceInvert(isSupportLuminanceInvert);
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Log.w(TAG, ioe);
|
Log.w(TAG, ioe);
|
||||||
@@ -717,9 +723,22 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否支持识别反色码,黑白颜色反转
|
||||||
|
* @param supportLuminanceInvert 默认为false,当返回true时表示支持,会增加识别率,但相应的也会增加性能消耗。
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CaptureHelper supportLuminanceInvert(boolean supportLuminanceInvert) {
|
||||||
|
isSupportLuminanceInvert = supportLuminanceInvert;
|
||||||
|
if(captureHandler!=null){
|
||||||
|
captureHandler.setSupportLuminanceInvert(isSupportLuminanceInvert);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置是否支持全屏扫码识别
|
* 设置是否支持全屏扫码识别
|
||||||
* @param fullScreenScan
|
* @param fullScreenScan 默认为false
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public CaptureHelper fullScreenScan(boolean fullScreenScan) {
|
public CaptureHelper fullScreenScan(boolean fullScreenScan) {
|
||||||
|
|||||||
@@ -102,31 +102,50 @@ final class DecodeHandler extends Handler {
|
|||||||
PlanarYUVLuminanceSource source = buildPlanarYUVLuminanceSource(data,width,height,isScreenPortrait);
|
PlanarYUVLuminanceSource source = buildPlanarYUVLuminanceSource(data,width,height,isScreenPortrait);
|
||||||
|
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
|
||||||
try {
|
|
||||||
rawResult = multiFormatReader.decodeWithState(bitmap);
|
|
||||||
} catch (Exception e) {
|
|
||||||
BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
|
|
||||||
try{
|
|
||||||
rawResult = multiFormatReader.decodeWithState(bitmap1);
|
|
||||||
}catch (Exception e1){
|
|
||||||
if(isSupportVerticalCode){
|
|
||||||
source = buildPlanarYUVLuminanceSource(data,width,height,!isScreenPortrait);
|
|
||||||
if(source!=null){
|
|
||||||
BinaryBitmap bitmap2 = new BinaryBitmap(new HybridBinarizer(source));
|
|
||||||
try{
|
|
||||||
rawResult = multiFormatReader.decodeWithState(bitmap2);
|
|
||||||
}catch (Exception e2){
|
|
||||||
|
|
||||||
}
|
boolean isReDecode;
|
||||||
}
|
try {
|
||||||
|
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||||
|
rawResult = multiFormatReader.decodeWithState(bitmap);
|
||||||
|
isReDecode = false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
isReDecode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isReDecode && handler.isSupportLuminanceInvert()){
|
||||||
|
try {
|
||||||
|
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source.invert()));
|
||||||
|
rawResult = multiFormatReader.decodeWithState(bitmap);
|
||||||
|
isReDecode = false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
isReDecode = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isReDecode){
|
||||||
|
try{
|
||||||
|
BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
|
||||||
|
rawResult = multiFormatReader.decodeWithState(bitmap);
|
||||||
|
isReDecode = false;
|
||||||
|
}catch (Exception e){
|
||||||
|
isReDecode = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isReDecode && isSupportVerticalCode){
|
||||||
|
source = buildPlanarYUVLuminanceSource(data,width,height,!isScreenPortrait);
|
||||||
|
if(source!=null){
|
||||||
|
try{
|
||||||
|
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||||
|
rawResult = multiFormatReader.decodeWithState(bitmap);
|
||||||
|
}catch (Exception e){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
|
||||||
multiFormatReader.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
multiFormatReader.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawResult != null) {
|
if (rawResult != null) {
|
||||||
@@ -157,7 +176,6 @@ final class DecodeHandler extends Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
@@ -211,7 +229,7 @@ final class DecodeHandler extends Handler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(length<width/5){
|
if(length < width/ 5){
|
||||||
|
|
||||||
Camera camera = cameraManager.getOpenCamera().getCamera();
|
Camera camera = cameraManager.getOpenCamera().getCamera();
|
||||||
if(camera!=null){
|
if(camera!=null){
|
||||||
|
|||||||
Reference in New Issue
Block a user