Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'com.android.application'
}

android {
compileSdk 32

Expand Down Expand Up @@ -48,8 +47,8 @@ dependencies {
implementation "com.airbnb.android:lottie:$lottieVersion"

//바코드 사용
implementation('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }
implementation 'com.google.zxing:core:3.4.1'
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
implementation 'com.google.zxing:core:2.0'

implementation 'com.google.android.gms:play-services-vision:18.0.0'
implementation 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'okhttp'
Expand All @@ -76,4 +75,9 @@ dependencies {
// If you want to additionally use the CameraX Extensions library
implementation "androidx.camera:camera-extensions:${camerax_version}"

//카메라, 바코드
implementation 'com.dynamsoft:dynamsoftbarcodereader:9.2.10@aar'
// Remove the following line if you want to use Android Camera sdk or your own sdk to control camera.
implementation 'com.dynamsoft:dynamsoftcameraenhancer:2.3.2@aar'

}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<activity
android:name=".scan.barcordscan.BarcodeScanActivity"
android:configChanges="screenSize|orientation" />
<activity
android:name=".scan.barcordscan.BarcodeCameraActivity"
android:configChanges="screenSize|orientation" />
<activity
android:name=".scan.camerascan.CameraScanActivity"
android:configChanges="screenSize|orientation" />
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/kr/co/whipping/scan/ScanActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import kr.co.whipping.R;
import kr.co.whipping.databinding.ActivityScanBinding;
import kr.co.whipping.scan.barcordscan.BarcodeScanActivity;
import kr.co.whipping.scan.barcordscan.IntentIntegrator;
import kr.co.whipping.scan.camerascan.CameraScanActivity;
import kr.co.whipping.scan.camerascan.InnerCameraActivity;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package kr.co.whipping.scan.barcordscan;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.Camera;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.ImageAnalysis;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.Preview;
import androidx.camera.core.UseCaseGroup;
import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.camera.view.PreviewView;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.util.Size;
import android.widget.TextView;

import com.dynamsoft.dbr.BarcodeReader;
import com.dynamsoft.dbr.BarcodeReaderException;
import com.dynamsoft.dbr.DBRLicenseVerificationListener;
import com.dynamsoft.dbr.EnumImagePixelFormat;
import com.dynamsoft.dbr.ImageData;
import com.dynamsoft.dbr.TextResult;
import com.google.common.util.concurrent.ListenableFuture;

import java.nio.ByteBuffer;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import kr.co.whipping.MainActivity;
import kr.co.whipping.R;

public class BarcodeCameraActivity extends AppCompatActivity {
private PreviewView previewView;
private ListenableFuture<ProcessCameraProvider> cameraProviderFuture;
private TextView resultView;
private ExecutorService exec;
private Camera camera;
private BarcodeReader dbr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
previewView = findViewById(R.id.previewView);
resultView = findViewById(R.id.resultView);
initDBR();
exec = Executors.newSingleThreadExecutor();
cameraProviderFuture = ProcessCameraProvider.getInstance(this);
cameraProviderFuture.addListener(new Runnable() {
@RequiresApi(api = Build.VERSION_CODES.R)
@Override
public void run() {
try {
ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
bindPreviewAndImageAnalysis(cameraProvider);
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
}
}, ContextCompat.getMainExecutor(this));


}


private class ImageData{
private int mWidth,mHeight,mStride;
byte[] mBytes;
ImageData(byte[] bytes ,int nWidth,int nHeight,int nStride){
mBytes = bytes;
mWidth = nWidth;
mHeight = nHeight;
mStride = nStride;
}
}



private void initDBR(){
BarcodeReader.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMTAxMzE4NjE0LVRYbE5iMkpwYkdWUWNtOXFYMlJpY2ciLCJvcmdhbml6YXRpb25JRCI6IjEwMTMxODYxNCIsImNoZWNrQ29kZSI6LTE1MjE0ODM1MzN9", new DBRLicenseVerificationListener() {
@Override
public void DBRLicenseVerificationCallback(boolean isSuccessful, Exception e) {
if (!isSuccessful) {
e.printStackTrace();
Log.d("dd", "라이센스 확인");
}
}
});
try {
dbr = new BarcodeReader();
} catch (BarcodeReaderException e) {
e.printStackTrace();
}
}

@RequiresApi(api = Build.VERSION_CODES.R)
@SuppressLint("UnsafeExperimentalUsageError")
private void bindPreviewAndImageAnalysis(@NonNull ProcessCameraProvider cameraProvider) {

int orientation = getApplicationContext().getResources().getConfiguration().orientation;
Size resolution;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
resolution = new Size(720, 1280);
}else{
resolution = new Size(1280, 720);
}

Preview.Builder previewBuilder = new Preview.Builder();
previewBuilder.setTargetResolution(resolution);
Preview preview = previewBuilder.build();

ImageAnalysis.Builder imageAnalysisBuilder=new ImageAnalysis.Builder();

//invert
//Camera2Interop.Extender ext = new Camera2Interop.Extender<>(imageAnalysisBuilder);
//ext.setCaptureRequestOption(CaptureRequest.CONTROL_EFFECT_MODE,CaptureRequest.CONTROL_EFFECT_MODE_NEGATIVE);

imageAnalysisBuilder.setTargetResolution(resolution)
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST);

ImageAnalysis imageAnalysis = imageAnalysisBuilder.build();

imageAnalysis.setAnalyzer(exec, new ImageAnalysis.Analyzer() {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void analyze(@NonNull ImageProxy image) {
int rotationDegrees =image.getImageInfo().getRotationDegrees();
TextResult[] results = null;
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
int nRowStride = image.getPlanes()[0].getRowStride();
int nPixelStride = image.getPlanes()[0].getPixelStride();
int length= buffer.remaining();
byte[] bytes= new byte[length];
buffer.get(bytes);
BarcodeCameraActivity.ImageData imageData= new BarcodeCameraActivity.ImageData(bytes,image.getWidth(), image.getHeight(),nRowStride *nPixelStride);
try {
results = dbr.decodeBuffer(imageData.mBytes,imageData.mWidth,imageData.mHeight, imageData.mStride, EnumImagePixelFormat.IPF_NV21);
} catch (BarcodeReaderException e) {
e.printStackTrace();
}

StringBuilder sb = new StringBuilder();
// sb.append("Found ").append(results.length).append(" barcode(s):\n");
for (int i = 0; i < results.length; i++) {
sb.append(results[i].barcodeText);
// sb.append("\n");
}
Log.d("DBR", sb.toString());
String barcode = sb.toString();
Log.d("DBR", barcode);
resultView.setText(sb.toString());


image.close();
if(barcode.length()>5) {
Log.d("result","result found");
Intent intent = new Intent(BarcodeCameraActivity.this, BarcodeScanActivity.class);
intent.putExtra("barcodenum", barcode);
Log.d("before activity start ","!!");
setResult(RESULT_OK, intent);
finish();
}
//
// image.close();
}
});

CameraSelector cameraSelector = new CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_BACK).build();
preview.setSurfaceProvider(previewView.getSurfaceProvider());

UseCaseGroup useCaseGroup = new UseCaseGroup.Builder()
.addUseCase(preview)
.addUseCase(imageAnalysis)
.build();
camera=cameraProvider.bindToLifecycle((LifecycleOwner)this, cameraSelector, useCaseGroup);
}

}

Loading