Skip to content

Commit

Permalink
修复放大的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
devilsen committed Aug 20, 2019
1 parent 5faf16e commit f2a5358
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 34 deletions.
Binary file added czxing/libs/arm64-v8a/libopencv_java4.so
Binary file not shown.
Binary file added czxing/libs/armeabi-v7a/libopencv_java4.so
Binary file not shown.
48 changes: 24 additions & 24 deletions czxing/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ include_directories(include)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}")

# 静态方式导入库
add_library(opencv_core STATIC IMPORTED)
add_library(opencv_imgcodecs STATIC IMPORTED)
add_library(opencv_imgproc STATIC IMPORTED)

add_library(cpufeatures STATIC IMPORTED)
add_library(tbb STATIC IMPORTED)
add_library(tegra_hal STATIC IMPORTED)
#add_library(opencv_core STATIC IMPORTED)
#add_library(opencv_imgcodecs STATIC IMPORTED)
#add_library(opencv_imgproc STATIC IMPORTED)
#
#add_library(cpufeatures STATIC IMPORTED)
#add_library(tbb STATIC IMPORTED)
#add_library(tegra_hal STATIC IMPORTED)
#
## 设置库路径
set_target_properties(opencv_core PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/libs/${ANDROID_ABI}/libopencv_core.a)
set_target_properties(opencv_imgcodecs PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/libs/${ANDROID_ABI}/libopencv_imgcodecs.a)
set_target_properties(opencv_imgproc PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/libs/${ANDROID_ABI}/libopencv_imgproc.a)

set_target_properties(cpufeatures PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/3rdparty/libs/${ANDROID_ABI}/libcpufeatures.a)
set_target_properties(tbb PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/3rdparty/libs/${ANDROID_ABI}/libtbb.a)
set_target_properties(tegra_hal PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/3rdparty/libs/${ANDROID_ABI}/libtegra_hal.a)
#set_target_properties(opencv_core PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/libs/${ANDROID_ABI}/libopencv_core.a)
#set_target_properties(opencv_imgcodecs PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/libs/${ANDROID_ABI}/libopencv_imgcodecs.a)
#set_target_properties(opencv_imgproc PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/libs/${ANDROID_ABI}/libopencv_imgproc.a)
#
#set_target_properties(cpufeatures PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/3rdparty/libs/${ANDROID_ABI}/libcpufeatures.a)
#set_target_properties(tbb PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/3rdparty/libs/${ANDROID_ABI}/libtbb.a)
#set_target_properties(tegra_hal PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../opencv/3rdparty/libs/${ANDROID_ABI}/libtegra_hal.a)

#add_library(opencv_java4 SHARED IMPORTED)
#set_target_properties(opencv_java4 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/libopencv_java4.so)
add_library(opencv_java4 SHARED IMPORTED)
set_target_properties(opencv_java4 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/libopencv_java4.so)

find_library(
log-lib
Expand All @@ -43,14 +43,14 @@ target_link_libraries(
czxing
ZXingCore

opencv_imgcodecs
opencv_imgproc
opencv_core

cpufeatures
tbb
tegra_hal
# opencv_java4
# opencv_imgcodecs
# opencv_imgproc
# opencv_core
#
# cpufeatures
# tbb
# tegra_hal
opencv_java4

jnigraphics
android
Expand Down
14 changes: 9 additions & 5 deletions czxing/src/main/cpp/JavaCallHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ JavaCallHelper::~JavaCallHelper() {
}

void JavaCallHelper::onResult(const ZXing::Result &result) {
if (result.format() == ZXing::BarcodeFormat::QR_CODE) {
if (result.resultPoints().size() < 2) {
return;
}
} else if (!result.isValid()) {
// if (result.format() == ZXing::BarcodeFormat::QR_CODE) {
// if (result.resultPoints().size() < 2) {
// return;
// }
// } else if (!result.isValid()) {
// return;
// }

if (!result.isValid() && !result.isBlurry()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion czxing/src/main/cpp/zxing/src/Result.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Result
}

bool isBlurry() const {
return resultPoints().size() > 2;
return resultPoints().size() >= 2;
}

DecodeStatus status() const {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package me.devilsen.czxing.util;

/**
* desc : 分辨率转换util
* date : 2019-08-20 17:07
*
* @author : dongSen
*/
public class ResolutionAdapterUtil {

private int resolutionWidth;
private int resolutionHeight;

private int cameraWidth;
private int cameraHeight;

private float ratioWidth;
private float ratioHeight;

public void setResolutionSize(int resolutionWidth, int resolutionHeight) {
this.resolutionWidth = resolutionWidth;
this.resolutionHeight = resolutionHeight;
setRatio();
}

public void setCameraSize(int cameraWidth, int cameraHeight) {
this.cameraWidth = cameraWidth;
this.cameraHeight = cameraHeight;
if (cameraWidth > cameraHeight) {
int temp = this.cameraWidth;
this.cameraWidth = this.cameraHeight;
this.cameraHeight = temp;
}
setRatio();
}

private void setRatio() {
if (ratioWidth == 0 && resolutionWidth != 0 && cameraWidth != 0) {
ratioWidth = 1.0f * cameraWidth / resolutionWidth;
}
if (ratioHeight == 0 && resolutionHeight != 0 && cameraHeight != 0) {
ratioHeight = 1.0f * cameraHeight / resolutionHeight;
}
}

public int getAdapterWidth(int width) {
if (ratioWidth != 0) {
return (int) (ratioWidth * width);
}
return width;
}

public int getAdapterHeight(int height) {
if (ratioHeight != 0) {
return (int) (ratioHeight * height);
}
return height;
}
}
10 changes: 10 additions & 0 deletions czxing/src/main/java/me/devilsen/czxing/view/BarCoderView.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import me.devilsen.czxing.code.CodeResult;
import me.devilsen.czxing.thread.ExecutorUtil;
import me.devilsen.czxing.util.BarCodeUtil;
import me.devilsen.czxing.util.ResolutionAdapterUtil;

/**
* @author : dongSen
Expand Down Expand Up @@ -41,6 +42,7 @@ abstract class BarCoderView extends FrameLayout implements Camera.PreviewCallbac
private long processLastTime;
private long mLastAutoZoomTime;
private long mDelayTime = ONE_HUNDRED_MILLISECONDS;
private ResolutionAdapterUtil resolutionAdapter;

public BarCoderView(Context context) {
this(context, null);
Expand Down Expand Up @@ -71,11 +73,14 @@ public void onStartPreview() {

mScanBoxView = new ScanBoxView(context);
addView(mScanBoxView, params);

resolutionAdapter = new ResolutionAdapterUtil();
}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
resolutionAdapter.setResolutionSize(right - left, bottom - top);
mCameraSurface.setScanBoxPoint(mScanBoxView.getScanBoxCenter());
}

Expand All @@ -98,6 +103,7 @@ public void onPreviewFrame(byte[] data, Camera camera) {
int top;
int rowWidth = size.width;
int rowHeight = size.height;
resolutionAdapter.setCameraSize(rowWidth, rowHeight);
// 这里需要把得到的数据也翻转
if (CameraUtil.isPortrait(getContext())) {
left = scanBoxRect.top - expandTop;
Expand All @@ -107,6 +113,10 @@ public void onPreviewFrame(byte[] data, Camera camera) {
top = scanBoxRect.top - expandTop;
}

left = resolutionAdapter.getAdapterWidth(left);
top = resolutionAdapter.getAdapterHeight(top);
scanBoxSize = resolutionAdapter.getAdapterWidth(scanBoxSize);

if (scanSequence < 5) {
onPreviewFrame(data, left, top, scanBoxSize, scanBoxSize, rowWidth, rowHeight);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void init() {

mBoxSize = BarCodeUtil.dp2px(context, 200);
mTopOffset = -BarCodeUtil.dp2px(context, 10);
// mBoxSizeOffset = BarCodeUtil.dp2px(context, 40);
mBoxSizeOffset = BarCodeUtil.dp2px(context, 40);

mBorderColor = resources.getColor(R.color.czxing_line_border);
mBorderSize = BarCodeUtil.dp2px(context, 1);
Expand Down Expand Up @@ -203,7 +203,6 @@ private void calFramingRect() {
mBoxSize = Math.min(viewWidth * 3 / 5, MAX_BOX_SIZE);
mBoxLeft = (viewWidth - mBoxSize) / 2;
mBoxTop = (viewHeight - mBoxSize) / 2 + mTopOffset;
mBoxSizeOffset = mBoxLeft;
mFramingRect = new Rect(mBoxLeft, mBoxTop, mBoxLeft + mBoxSize, mBoxTop + mBoxSize);
}

Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ android {

dependencies {

// implementation project(':czxing')
implementation 'me.devilsen:CZXing:0.8.3'
implementation project(':czxing')
// implementation 'me.devilsen:CZXing:0.8.3'

implementation rootProject.ext.appcompat
testImplementation rootProject.ext.junit
Expand Down

0 comments on commit f2a5358

Please sign in to comment.