first imageI am working on app in react native to scan testing strip as shown in images.I have to find C,G,M point if they contain red lines using camera.I have to scan and get reading where the redlines shown after test using mobile camera.any solutions or flow how to do it in react native?even in android or ios?
I am using nativemodules for native code implementation.
here is the code. I have logic that first turn image into grayscale then black and white then get corodinates of the line.
Here is the code:
public class ConverttoBitmap extends ReactContextBaseJavaModule { public Context context; public ConverttoBitmap(ReactApplicationContext reactContext) { super(reactContext); this.context = reactContext; } @Override public String getName() { return "Bitmap"; } @ReactMethod public void getPixels(String filePath, final Promise promise) { try { WritableNativeMap result = new WritableNativeMap(); WritableNativeArray pixels = new WritableNativeArray(); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.singleline); Log.i("ssssss", bitmap+","+filePath); if (bitmap == null) { promise.reject("Failed to decode. Path is incorrect or image is corrupted"); return; } Bitmap imgnew; imgnew = toGrayscale(bitmap); imgnew = convertBitmap(imgnew); saveImageToStorage(imgnew); promise.resolve(imgnew); } catch (Exception e) { promise.reject(e); } } public Bitmap convertBitmap(Bitmap input) { Bitmap output = Bitmap.createBitmap(input.getWidth(), input.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); Paint colorFilterMatrixPaint = new Paint(Paint.ANTI_ALIAS_FLAG); colorFilterMatrixPaint.setColorFilter(new ColorMatrixColorFilter(new float[] { 90.f, 90.f, 90.f, 0.f, -255.f * 128, 90.f, 90.f, 90.f, 0.f, -255.f * 128, 90.f, 90.f, 90.f, 0.f, -255.f * 128, 0f, 0f, 0f, 1f, 0f })); canvas.drawBitmap(input, 0, 0, colorFilterMatrixPaint); return output; } private void saveImageToStorage(Bitmap bitmap) throws IOException { OutputStream imageOutStream; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.DISPLAY_NAME,"image_screenshot.jpg"); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); values.put(MediaStore.Images.Media.RELATIVE_PATH,Environment.DIRECTORY_PICTURES + File.pathSeparator +"AppName"); Uri uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); Log.i("output", String.valueOf(uri)); imageOutStream = context.getContentResolver().openOutputStream(uri); } else { String imagesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES). toString() +"/AppName"; File image = new File(imagesDir, "image_screenshot.jpg"); Log.i("output", String.valueOf(image)); imageOutStream = new FileOutputStream(image); } bitmap.compress(Bitmap.CompressFormat.JPEG, 100, imageOutStream); imageOutStream.close(); } public Bitmap toGrayscale(Bitmap bitmap) { int width, height; height = bitmap.getHeight(); width = bitmap.getWidth(); Log.i("GrayScale", width+"x"+height); Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bitmap, 0, 0, paint); Log.i("GrayScale", String.valueOf(bmpGrayscale)); return bmpGrayscale; }}
Please solution to find text point C,G,M who has red line.
Please any solution how to scan red lines and get text that shows reading that has redline?