diff --git a/fourcell/.gitignore b/fourcell/.gitignore new file mode 100644 index 0000000..0a764a4 --- /dev/null +++ b/fourcell/.gitignore @@ -0,0 +1 @@ +env diff --git a/fourcell/README.md b/fourcell/README.md new file mode 100644 index 0000000..f3865e4 --- /dev/null +++ b/fourcell/README.md @@ -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 \ No newline at end of file diff --git a/fourcell/analyze.py b/fourcell/analyze.py new file mode 100644 index 0000000..454022b --- /dev/null +++ b/fourcell/analyze.py @@ -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 \ No newline at end of file diff --git a/fourcell/notes/example1.jpg b/fourcell/notes/example1.jpg new file mode 100644 index 0000000..43fb8e2 Binary files /dev/null and b/fourcell/notes/example1.jpg differ diff --git a/fourcell/notes/example1.py b/fourcell/notes/example1.py new file mode 100644 index 0000000..9ae02dd --- /dev/null +++ b/fourcell/notes/example1.py @@ -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) \ No newline at end of file diff --git a/fourcell/requirements.txt b/fourcell/requirements.txt new file mode 100644 index 0000000..1db7aea --- /dev/null +++ b/fourcell/requirements.txt @@ -0,0 +1 @@ +opencv-python \ No newline at end of file