Ask Your Question

Can anyone please help me in detection of the pins?

asked 2019-12-21 00:48:36 -0500

Ameya gravatar image

Hello everyone, I am developing one computer vision application using OpenCV, C++, Cvblobs etc. I want to inspect one connector part having 6 pins. The goal is to detect the pins accurately. I am attaching one image for the pins and what I want to detect. Any help will be really appreciated.

edit retag flag offensive close merge delete


using OpenCV, C++, Cvblobs etc

please show, what you have, so far.

I am attaching one image

did you ?

berak gravatar imageberak ( 2019-12-21 04:36:12 -0500 )edit

Hello Berak, Thanks for showing interest in my question. Unfortuanately I am not able to attach the images. I dont know the reson but its not getting uploaded. Can you please give me your email id?

Ameya gravatar imageAmeya ( 2019-12-21 05:22:04 -0500 )edit

Go back to your first comment and click image.

supra56 gravatar imagesupra56 ( 2019-12-21 05:26:16 -0500 )edit

attaching one image where red squares represent the pins I want to detect.

Also find the original image

Ameya gravatar imageAmeya ( 2019-12-21 05:35:15 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-12-21 12:25:55 -0500

supra56 gravatar image

Here is code:

#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)


image description

edit flag offensive delete link more


Btw, I've forgotten to draw rectangle. As I'm running out of time for Xmas season. Merry Xmas and Happy New Years.

supra56 gravatar imagesupra56 ( 2019-12-21 12:28:51 -0500 )edit

OOOPPpppss. My apologized. The above code is written in python. Someone may help to translate to c++.

supra56 gravatar imagesupra56 ( 2019-12-21 12:33:10 -0500 )edit

Question Tools

1 follower


Asked: 2019-12-21 00:44:44 -0500

Seen: 165 times

Last updated: Dec 21 '19