Ask Your Question
0

Can anyone please help me in detection of the pins?

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

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

Comments

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 -0600 )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 -0600 )edit

Go back to your first comment and click image.

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

attaching one image where red squares represent the pins I want to detect. https://drive.google.com/file/d/1UDUT...

Also find the original image https://drive.google.com/file/d/1dRIN...

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

1 answer

Sort by ยป oldest newest most voted
0

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

supra56 gravatar image

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

edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 440 times

Last updated: Dec 21 '19