Merge remote-tracking branch 'origin/main'

This commit is contained in:
Matt McWilliams 2022-11-08 21:10:50 -05:00
commit e5d9d654ac
6 changed files with 74 additions and 0 deletions

1
fourcell/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
env

16
fourcell/README.md Normal file
View File

@ -0,0 +1,16 @@
# Four Cell Script
Two scripts:
1. Analyzes a calibration sheet on the plotter to generate a template.
2. Takes cells and inserts them into the template 4 at a time.
## Analysis Steps
1. Locate positions of 6 hole punches
2. Orient to square position
3. Find all 4 fiducials
4. Calculate their position relative to the hole punches
5. Create a template
6. Use the template-filling script to recreate calibration page as a proof to be checked on a lightbox

18
fourcell/analyze.py Normal file
View File

@ -0,0 +1,18 @@
import sys
import cv2
import numpy as np
if len(sys.argv) < 2:
print('Please provide path to image for analysis')
exit(1)
if len(sys.argv) < 3:
print('Please provide path to template file to create')
exit(2)
scanImage = sys.argv[-2]
templateFile = sys.argv[-1]
print(f'Analyzing {scanImage} and creating {templateFile}')
#https://stackoverflow.com/questions/51456660/opencv-detecting-drilled-holes

BIN
fourcell/notes/example1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 KiB

View File

@ -0,0 +1,38 @@
#https://stackoverflow.com/questions/51456660/opencv-detecting-drilled-holes
import cv2
import numpy as np
img = cv2.imread("./example1.jpg")
# cv2.imshow("original", img)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# cv2.imshow("gray", gray)
blur = cv2.medianBlur(gray, 31)
# cv2.imshow("blur", blur)
ret, thresh = cv2.threshold(blur, 127, 255, cv2.THRESH_OTSU)
# cv2.imshow("thresh", thresh)
canny = cv2.Canny(thresh, 75, 200)
# cv2.imshow('canny', canny)
contours, hierarchy = cv2.findContours(canny, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
contour_list = []
for contour in contours:
approx = cv2.approxPolyDP(contour, 0.01 * cv2.arcLength(contour, True), True)
area = cv2.contourArea(contour)
if 5000 < area < 15000:
contour_list.append(contour)
msg = "Total holes: {}".format(len(approx)//2)
cv2.putText(img, msg, (20, 40), cv2.FONT_HERSHEY_PLAIN, 2, (0, 0, 255), 2, cv2.LINE_AA)
cv2.drawContours(img, contour_list, -1, (0, 255, 0), 2)
cv2.imshow('Objects Detected', img)
cv2.imwrite("detected_holes.png", img)
cv2.waitKey(0)

View File

@ -0,0 +1 @@
opencv-python