Toshkent axborot texnologiyalari universiteti


Download 306.03 Kb.
bet3/3
Sana22.11.2021
Hajmi306.03 Kb.
#176506
1   2   3
Bog'liq
suniy intelekt 10

Dastur codi:

public class MainActivity extends AppCompatActivity {

private static final String TAG = "TAG";
private TextView mTextView;
private SurfaceView mCameraView;

@Override


protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mCameraView = findViewById(R.id.surfaceView);
mTextView = findViewById(R.id.text_view);
startCameraSource();

}

private void startCameraSource() {



final TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();

if (!textRecognizer.isOperational()) {


Log.w(TAG, "Detector dependencies not loaded yet");
} else {

CameraSource mCameraSource = new CameraSource.Builder(getApplicationContext(), textRecognizer)


.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1280, 1024)
.setAutoFocusEnabled(true)
.setRequestedFps(2.0f)
.build();

mCameraView.getHolder().addCallback(new SurfaceHolder.Callback() {


@Override
public void surfaceCreated(SurfaceHolder holder) {
try {

if (ActivityCompat.checkSelfPermission(getApplicationContext(),


Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(MainActivity.this,


new String[]{Manifest.permission.CAMERA},
1001);
return;
}
mCameraSource.start(mCameraView.getHolder());
} catch (IOException e) {
e.printStackTrace();
}
}

@Override


public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}

@Override


public void surfaceDestroyed(SurfaceHolder holder) {
mCameraSource.stop();
}
});

//Set the TextRecognizer's Processor.


textRecognizer.setProcessor(new Detector.Processor() {
@Override
public void release() {
}

@Override


public void receiveDetections(Detector.Detections detections) {
final SparseArray items = detections.getDetectedItems();
if (items.size() != 0) {

mTextView.post(() -> {


StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < items.size(); i++) {
TextBlock item = items.valueAt(i);
stringBuilder.append(item.getValue());
stringBuilder.append("\n");
}
mTextView.setText(stringBuilder.toString());
});
}
}
});
}
}
}

Dastur natijasi:





10-11 amaliy ish

214-17 Solijonov Otabek.




Download 306.03 Kb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling