Hello,
I’m building a scanner app for identity card. After taking image from camera, I’m using OpenCV.js to detect identity card and crop it.
According to what i search, I know the steps to do what I want are:
Convert image to gray
Blur it
Draw canny
Find contours
Draw contours
Crop it
The source image:
Result I wish:
But I’m stucking at step find contours to draw, right now I just can make something like this:
I need that step to complete:
Below is my code:
let src = cv.imread('img');
let dst = new cv.Mat();
let ksize = new cv.Size(5, 5);
cv.cvtColor(src, dst, cv.COLOR_RGBA2GRAY);
cv.Canny(dst, dst, 75, 200, 3, false);
cv.threshold(dst, dst, 80, 255, cv.THRESH_BINARY_INV);
cv.imshow('canvasOutput', dst);
src.delete();
dst.delete();
Is there anyone know how to do this, help me please!
Thank you so much!!!
2 Likes
deko
February 12, 2020, 11:04pm
2
hi,
did you find a solution for this?
I think that what you need es Rect and roi:
This should do the trick:
let src = cv.imread(‘img’);
let dst = new cv.Mat();
// You can try more different parameters
let rect = new cv.Rect(100, 100, 200, 200);
dst = src.roi(rect);
cv.imshow(‘canvasOutput’, dst);
src.delete();
dst.delete();
Hi, maybe a stupid question, but how did you integrate OpenCV.js within your ionic app to be able to get your code working?
I might actually have found a way to implement it here:
I am trying to develop a simple image processing mobile application using the Ionic Framework (version 4). I decided to use the OpenCV.js library and the way I am adding it to my ionic project is:
I put the opencv.js file in app/assets/lib/opencv.js
I added
"scripts": [
"src/assets/lib/opencv.js"
]
in my angular.json file.
I put declare var cv: any; on top of any ts file that I needed to use the opencv library in and then I just use cv to reference an …
Is this how you did it?