# Bent pins in connector

**URL:** <https://forum.opencv.org/t/bent-pins-in-connector/4133>\
**Category:** Python\
**Tags:** contours, canny, imgproc\
**Created:** [July 2, 2021, 11:07am UTC](https://forum.opencv.org/t/bent-pins-in-connector/4133 "2021-07-02T11:07:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antrac1t](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@Antrac1t](https://forum.opencv.org/u/Antrac1t)\
**Post date:** [July 2, 2021, 11:07am UTC](https://forum.opencv.org/t/bent-pins-in-connector/4133/1 "2021-07-02T11:07:13Z")

</div>

Hi,  
I started working on checking data connector for servers where we facing with bent pins problems (just edge pins can be bent) and sometimes with foam contamination (part of foam cover 1-n pins).

Part of first problem is almost solved. Using contours i am trying find in ROI if there is any contour which mean that connector is damaged (i am not saing that this is good aproach but seems that working). Second problem is to check if the pin itself is bent. So my idea was to find circles from contour (which didn’t work - not find everything) and then try to calculate distance between circles (variable where will be defined range for OK pins and the rest is NG - calculation should be for each pair). This approchac can also help to find it there is any foam contamination - i can compare number of circle contour with number of pins (36 pins).

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/4/4673eb4a3ee9f03ee85bfba9c040cf1a53f1b420.jpeg)

If there will be anybody who have any idea, i will just be happy. thank you

[there is reference img](https://i.postimg.cc/59qDMKrk/con-check-05.png)

```auto
import argparse
import cv2
import numpy as np
import imutils

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", type=str, required=True,
	help="path to input image")
args = vars(ap.parse_args())

image = cv2.imread(args["image"])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3,3), 0)

cv2.imshow("Original", image)
cv2.imshow("Blurred", blurred)

blurImg = cv2.Canny(blurred, 130, 230)

croppedtop = blurImg[53:70 , 92:513]
croppedbot = blurImg[387:410 , 96:507]

rgbtop = cv2.cvtColor(croppedtop, cv2.COLOR_GRAY2BGR)
rgbbot = cv2.cvtColor(croppedbot, cv2.COLOR_GRAY2BGR)

hsvtop = cv2.cvtColor(rgbtop , cv2.COLOR_BGR2HSV)
hsvbot = cv2.cvtColor(rgbbot , cv2.COLOR_BGR2HSV)

lower_white = np.array([0,0,180])
higher_white = np.array([255,255,255])
Result_top = cv2.inRange(hsvtop, lower_white, higher_white)
Result_bot = cv2.inRange(hsvbot, lower_white, higher_white)

cv2.imshow("Tight Edge Map", blurImg)
cv2.imshow("Result bot",Result_bot )
cv2.imshow("Result top",Result_top )

if cv2.countNonZero(Result_bot) > 0 or cv2.countNonZero(Result_top) > 0:
    print('Damaged slot!')
    #cnts = cv2.findContours(Result_bot.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    #cnts = imutils.grab_contours(cnts)
    #print("Total damages is: {}".format(len(cnts)))
	
else:
    print('OK!')
cv2.waitKey(0)

```

---

<div class="post-metadata">

**Author:** ![Antrac1t](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@Antrac1t](https://forum.opencv.org/u/Antrac1t)\
**Post date:** [July 4, 2021, 9:05pm UTC](https://forum.opencv.org/t/bent-pins-in-connector/4133/2 "2021-07-04T21:05:58Z")

</div>

Hi,  
still continue to figure out how to detect bent pins and seems that i have small progress. For this moment i am able to find all pins + 4 fake detection which i need remove. For removing any fake “pins” i will create map of connector where every couple of pin will have own ROI and then i hope that result will be 100% right. Next step will be measure distance between two points and decide if connector is damaged or not.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/a/ad31e5239cf0d24e073bb104ebf0f1f335030e03.jpeg)

---

<div class="post-metadata">

**Author:** ![Antrac1t](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@Antrac1t](https://forum.opencv.org/u/Antrac1t)\
**Post date:** [July 13, 2021, 1:00pm UTC](https://forum.opencv.org/t/bent-pins-in-connector/4133/3 "2021-07-13T13:00:54Z")

</div>

Hi,  
small progress about checking if pins are bend or not. As you can see i create array for each pin when i am try to calculate distance between two contacts. Next step will be to rewrite code for IP camera, currently i am testing on stative img

![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/4/4775b6cba019b654fe4e9f4641fa47fdbacf13aa.png)
