Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is code:

#!/usr/bin/python37
#OpenCV 4.1.2; Raspberry pi 3b/4
#Date: 20th December, 2019

import cv2 as cv

img = cv.imread('pad.jpg')
img = cv.resize(img, (640, 732))

gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

edges = cv.Canny(gray, 331, 999)
contours, _ = cv.findContours(edges.copy(), cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)

for cnt in contours:
    area = cv.contourArea(cnt)
    peri = cv.arcLength(cnt, True)
    approx = cv.approxPolyDP(cnt, 0.19*peri, True)
    if area > 2 and len(approx) == 2:
        cv.drawContours(img, [approx], -1, (0, 255, 0), 3)

cv.imwrite('solder_pads1.jpg', img)
cv.imshow('Image edges', edges)
cv.imshow('Image', img)
cv.waitKey(0)

Output:

image description