Adjusting/improving line removal #12

Merged
ewellenr merged 18 commits from autocropper-test into autocropper 2023-10-30 14:50:00 -04:00
2 changed files with 26 additions and 16 deletions

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2535,
"execution_count": 136,
"metadata": {},
"outputs": [],
"source": [
@ -15,16 +15,16 @@
},
{
"cell_type": "code",
"execution_count": 2536,
"execution_count": 137,
"metadata": {},
"outputs": [],
"source": [
"img = cv2.imread('./test_images/IMG_7605.jpg')"
"img = cv2.imread('./test_images/IMG_7640.jpg')"
]
},
{
"cell_type": "code",
"execution_count": 2537,
"execution_count": 138,
"metadata": {},
"outputs": [],
"source": [
@ -99,7 +99,7 @@
},
{
"cell_type": "code",
"execution_count": 2538,
"execution_count": 139,
"metadata": {},
"outputs": [],
"source": [
@ -118,6 +118,7 @@
"\n",
"\n",
"def removeCardinalLines(image, horizontal=False):\n",
" # kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))\n",
" axis = 0\n",
" if (horizontal):\n",
" cardinal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (25,1))\n",
@ -125,6 +126,7 @@
" else:\n",
" cardinal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,15))\n",
" lines = cv2.morphologyEx(image, cv2.MORPH_OPEN, cardinal_kernel, iterations=2)\n",
" # lines = cv2.morphologyEx(lines, cv2.MORPH_OPEN, kernel, iterations=2)\n",
" # return lines\n",
"\n",
" mask = np.zeros(image.shape, dtype=np.uint8)\n",
@ -165,7 +167,10 @@
" # print(rect[1][1-axis])\n",
" # print(rect[1][axis])\n",
" if (rect[1][axis] < meddim/2 and rect[1][1-axis] > image.shape[axis]/5):\n",
" box = cv2.boxPoints(rect)\n",
" adjustedrect = rect\n",
" adjustedrect[1][0] += 3\n",
" adjustedrect[1][1] += 3\n",
" box = cv2.boxPoints(adjustedrect)\n",
" box = np.intp(box)\n",
" # boxes.append(box) \n",
" # mask = cv2.drawContours(mask, [box], -1, 255, thickness=2)\n",
@ -223,7 +228,7 @@
},
{
"cell_type": "code",
"execution_count": 2539,
"execution_count": 140,
"metadata": {},
"outputs": [],
"source": [
@ -245,7 +250,7 @@
},
{
"cell_type": "code",
"execution_count": 2540,
"execution_count": 141,
"metadata": {},
"outputs": [],
"source": [
@ -422,15 +427,15 @@
},
{
"cell_type": "code",
"execution_count": 2541,
"execution_count": 142,
"metadata": {},
"outputs": [],
"source": [
"def cropclarifying(image):\n",
" whitedbackground = whiteoutbackground(image)\n",
" whitedbackground = mf.whiteoutbackground(image)\n",
" # return whitedbackground\n",
" \n",
" textrefined = textClarifying(whitedbackground)\n",
" textrefined = mf.textClarifying(whitedbackground)\n",
" # return textrefined\n",
" #maybe now is when I put in the line removing function\n",
" \n",
@ -462,7 +467,7 @@
},
{
"cell_type": "code",
"execution_count": 2542,
"execution_count": 143,
"metadata": {},
"outputs": [],
"source": [
@ -474,7 +479,7 @@
},
{
"cell_type": "code",
"execution_count": 2543,
"execution_count": 144,
"metadata": {},
"outputs": [],
"source": [
@ -488,7 +493,7 @@
},
{
"cell_type": "code",
"execution_count": 2544,
"execution_count": 145,
"metadata": {},
"outputs": [],
"source": [
@ -500,7 +505,7 @@
},
{
"cell_type": "code",
"execution_count": 2546,
"execution_count": 146,
"metadata": {},
"outputs": [],
"source": [

View File

@ -535,6 +535,7 @@ def whiteoutbackground(image):
return test
def removeCardinalLines(image, horizontal=False):
# kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))
axis = 0
if (horizontal):
cardinal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (25,1))
@ -542,6 +543,7 @@ def removeCardinalLines(image, horizontal=False):
else:
cardinal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,15))
lines = cv2.morphologyEx(image, cv2.MORPH_OPEN, cardinal_kernel, iterations=2)
# lines = cv2.morphologyEx(lines, cv2.MORPH_OPEN, kernel, iterations=2)
# return lines
mask = np.zeros(image.shape, dtype=np.uint8)
@ -582,7 +584,10 @@ def removeCardinalLines(image, horizontal=False):
# print(rect[1][1-axis])
# print(rect[1][axis])
if (rect[1][axis] < meddim/2 and rect[1][1-axis] > image.shape[axis]/5):
box = cv2.boxPoints(rect)
adjustedrect = rect
adjustedrect[1][0] += 3
adjustedrect[1][1] += 3
box = cv2.boxPoints(adjustedrect)
box = np.intp(box)
# boxes.append(box)
# mask = cv2.drawContours(mask, [box], -1, 255, thickness=2)