Good afternoon Ale,
I tried to work out your random thoughts on this problem but didn’t found any solutions yet
For Thought 1, I can’t do that. The code needs to be executed within 4 seconds and the work, other than the OpenCV work, is taking 2500ms so I can’t do multiple searches.
For Thought 2, I converted the base and template image to grayscale using the Sharp Library but it didn’t work.
For Thought 3. I am not sure that I had done it in the right way but it didn’t work either.
This was the code i used for the 3rd thought:
sharp(imagePath).trim().toBuffer()
.then(async (buffer) => {
/**
* Removed White Space
* Now find the location of dashed line part with openCV
*/
let trimImage = sharp(buffer);
let { width, height } = await trimImage.metadata();
let findBuffer = await sharp("./findAA.jpeg").resize(width).toBuffer();
let img1 = await loadImage(buffer);
let img2 = await loadImage(findBuffer);
img1 = cv.imread(img1);
img2 = cv.imread(img2);
let canIn = createCanvas();
cv.imshow(canIn, img1);
let canFi = createCanvas();
cv.imshow(canFi, img2);
let src = cv.imread(canIn);
const temp = cv.imread(canFi);
let dest = new cv.Mat();
let mask = new cv.Mat();
cv.threshold(src, dest, 177, 200, cv.THRESH_BINARY);
cv.threshold(temp, mask, 177, 200, cv.THRESH_BINARY);
cv.matchTemplate(src, temp, dest, cv.TM_CCOEFF_NORMED, mask);
let result = cv.minMaxLoc(dest, mask);
let maxPoint = result.maxLoc;
src.delete(); dest.delete(); mask.delete();
// Position from top where the dashed line was found
let cvTop = maxPoint.y + 8;
trimImage
.extract({ top: cvTop, left: 0, width: width, height: (height - cvTop) })
.toFile("./croppedFinal.jpeg");
})
For Thought 4, I don’t know what it is. Just started with OpenCV. So i don’t have much knowledge of its patterns.
For Thought 5, I Followed the link but I didn’t get it. sry.
Below is that greenish background image on which the code is not working quite well.