IDK tbh
Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
This commit is contained in:
parent
3aee49f236
commit
a564908fbc
@ -2,7 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 106,
|
||||
"execution_count": 514,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -15,7 +15,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 107,
|
||||
"execution_count": 515,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -55,7 +55,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 108,
|
||||
"execution_count": 516,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -77,7 +77,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 109,
|
||||
"execution_count": 517,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -91,7 +91,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 110,
|
||||
"execution_count": 518,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -102,7 +102,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 111,
|
||||
"execution_count": 519,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -322,7 +322,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 112,
|
||||
"execution_count": 520,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -461,7 +461,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 113,
|
||||
"execution_count": 521,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -489,7 +489,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 114,
|
||||
"execution_count": 522,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -542,7 +542,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 115,
|
||||
"execution_count": 523,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -591,7 +591,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 116,
|
||||
"execution_count": 524,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -631,7 +631,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 117,
|
||||
"execution_count": 525,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -647,6 +647,34 @@
|
||||
" #IDEA, try cropping the image for triangle threshold. not too sure how triangle threshold actually works\n",
|
||||
" ogshape = croppedimage.shape\n",
|
||||
" miniimage = mf.ResizeWithAspectRatio(croppedimage, width=1000) if (ogshape[1] > ogshape[0]) else mf.ResizeWithAspectRatio(croppedimage, height=1000)\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" \n",
|
||||
" # hsvmini = cv2.cvtColor(miniimage, cv2.COLOR_BGR2HSV)\n",
|
||||
" # grayh = hsvmini[:,:,1]\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" # grayg = cv2.cvtColor(miniimage,cv2.COLOR_BGR2GRAY)\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" \n",
|
||||
" # threshh = cv2.threshold(grayh, 0, 255, cv2.THRESH_OTSU)[1]\n",
|
||||
" # threshh = 255-threshh\n",
|
||||
" \n",
|
||||
" # threshg = cv2.threshold(grayg, 0, 255, cv2.THRESH_OTSU)[1]\n",
|
||||
" \n",
|
||||
" # window = grayh.shape[1]//10\n",
|
||||
" # if window % 2 == 0:\n",
|
||||
" # window += 1\n",
|
||||
" \n",
|
||||
" # grayh = 255-grayh\n",
|
||||
" # threshha = cv2.adaptiveThreshold(grayh, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, window, 4)\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" \n",
|
||||
" \n",
|
||||
" \n",
|
||||
" \n",
|
||||
" # miniimage = croppedimage\n",
|
||||
" \n",
|
||||
" hsvmini = cv2.cvtColor(miniimage, cv2.COLOR_BGR2HSV)\n",
|
||||
@ -705,10 +733,11 @@
|
||||
"\n",
|
||||
" # threshold\n",
|
||||
" # thresh = cv2.threshold(gray, 170, 255, cv2.THRESH_BINARY)[1]\n",
|
||||
" thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)[1]\n",
|
||||
" # thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)[1]\n",
|
||||
" # thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_TRIANGLE)[1]\n",
|
||||
"\n",
|
||||
" # thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, window, 5)\n",
|
||||
" gray = 255-gray\n",
|
||||
" thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, window, 4)\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" # thresh = cv2.bitwise_and(thresh, thresh1)\n",
|
||||
@ -717,7 +746,7 @@
|
||||
" # temp = cv2.bitwise_and(thresh, 255-canniedgray)\n",
|
||||
" # return temp, (0,0,0,0)\n",
|
||||
" \n",
|
||||
" thresh = 255-thresh\n",
|
||||
" # thresh = 255-thresh\n",
|
||||
"\n",
|
||||
" # return thresh, (0,0,0,0)\n",
|
||||
"\n",
|
||||
@ -742,7 +771,7 @@
|
||||
" morphmask = miniblank.copy()\n",
|
||||
" morphmask = cv2.drawContours(morphmask, [big_contour], -1, 255, thickness=cv2.FILLED) \n",
|
||||
" \n",
|
||||
" # return morphmask, (0,0,0,0)\n",
|
||||
" return morphmask, (0,0,0,0)\n",
|
||||
" \n",
|
||||
" dim = int(min(thresh.shape)/10)\n",
|
||||
" bkernel = cv2.getStructuringElement(cv2.MORPH_RECT, (dim, dim))\n",
|
||||
@ -811,7 +840,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 118,
|
||||
"execution_count": 526,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -869,7 +898,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 119,
|
||||
"execution_count": 527,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -926,7 +955,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 120,
|
||||
"execution_count": 528,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -970,7 +999,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 121,
|
||||
"execution_count": 529,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -1005,7 +1034,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 122,
|
||||
"execution_count": 530,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -1014,7 +1043,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 123,
|
||||
"execution_count": 531,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -1030,7 +1059,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 124,
|
||||
"execution_count": 532,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -1044,7 +1073,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 125,
|
||||
"execution_count": 533,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -1056,7 +1085,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 126,
|
||||
"execution_count": 534,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -1065,7 +1094,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 127,
|
||||
"execution_count": 535,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -1075,7 +1104,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 128,
|
||||
"execution_count": 536,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -1105,14 +1134,14 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 129,
|
||||
"execution_count": 537,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"average time: 0.1075682853584859(s)\n"
|
||||
"average time: 0.10459864317481198(s)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -1123,7 +1152,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 130,
|
||||
"execution_count": 538,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -1133,7 +1162,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 131,
|
||||
"execution_count": 539,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -1142,7 +1171,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 132,
|
||||
"execution_count": 540,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 26,
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -10,14 +10,26 @@
|
||||
"import pathlib\n",
|
||||
"import shutil\n",
|
||||
"import cv2\n",
|
||||
"import numpy as np"
|
||||
"import numpy as np\n",
|
||||
"import time"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 27,
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/usr/local/lib/python3.10/dist-packages/torchvision/datapoints/__init__.py:12: UserWarning: The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. While we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: https://github.com/pytorch/vision/issues/6753, and you can also check out https://github.com/pytorch/vision/issues/7319 to learn more about the APIs that we suspect might involve future changes. You can silence this warning by calling torchvision.disable_beta_transforms_warning().\n",
|
||||
" warnings.warn(_BETA_TRANSFORMS_WARNING)\n",
|
||||
"/usr/local/lib/python3.10/dist-packages/torchvision/transforms/v2/__init__.py:54: UserWarning: The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. While we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: https://github.com/pytorch/vision/issues/6753, and you can also check out https://github.com/pytorch/vision/issues/7319 to learn more about the APIs that we suspect might involve future changes. You can silence this warning by calling torchvision.disable_beta_transforms_warning().\n",
|
||||
" warnings.warn(_BETA_TRANSFORMS_WARNING)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import sys\n",
|
||||
"sys.path.insert(0, '/mnt/code/autocropper')\n",
|
||||
@ -26,7 +38,16 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 28,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# print(sys.path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -35,7 +56,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -46,7 +67,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -148,7 +169,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -159,6 +180,8 @@
|
||||
" \n",
|
||||
" filenames = next(os.walk(imagespath), (None, None, []))[2]\n",
|
||||
" \n",
|
||||
" tdiffs = []\n",
|
||||
" \n",
|
||||
" for filename in filenames:\n",
|
||||
" suffix = pathlib.Path(filename).suffix\n",
|
||||
" if (suffix not in imagefileextensions):\n",
|
||||
@ -170,15 +193,19 @@
|
||||
" continue\n",
|
||||
" img = cv2.imread(imagespath+filename)\n",
|
||||
" # print(img)\n",
|
||||
" t1 = time.time()\n",
|
||||
" autocropped = mf.houghlineprocessing(img)\n",
|
||||
" tdiffs.append(time.time() - t1)\n",
|
||||
" cv2.imwrite(datasetpath+subpathtoaugmentedfiles+filename, autocropped)\n",
|
||||
" tdiffs = np.array(tdiffs)\n",
|
||||
" print(\"average time: \" + str(np.mean(tdiffs))+\"(s)\")\n",
|
||||
" \n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -200,16 +227,22 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 33,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'IMG_7736.jpg': '0.jpg', 'IMG_7737.jpg': '1.jpg', 'IMG_7738.jpg': '2.jpg', 'IMG_7739.jpg': '3.jpg', 'IMG_7740.jpg': '4.jpg', 'IMG_7741.jpg': '5.jpg', 'IMG_7742.jpg': '6.jpg', 'IMG_7743.jpg': '7.jpg', 'IMG_7744.jpg': '8.jpg', 'IMG_7745.jpg': '9.jpg', 'IMG_7747.jpg': '10.jpg', 'IMG_7748.jpg': '11.jpg'}\n",
|
||||
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n",
|
||||
"{}\n"
|
||||
"{}\n",
|
||||
"[]\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'IMG_7594.jpg': '0.jpg', 'IMG_7604.jpg': '1.jpg', 'IMG_7605.jpg': '2.jpg', 'IMG_7640.jpg': '3.jpg', 'IMG_7736.jpg': '4.jpg', 'IMG_7737.jpg': '5.jpg', 'IMG_7738.jpg': '6.jpg', 'IMG_7739.jpg': '7.jpg', 'IMG_7740.jpg': '8.jpg', 'IMG_7741.jpg': '9.jpg', 'IMG_7742.jpg': '10.jpg', 'IMG_7743.jpg': '11.jpg', 'IMG_7744.jpg': '12.jpg', 'IMG_7745.jpg': '13.jpg', 'IMG_7747.jpg': '14.jpg', 'IMG_7748.jpg': '15.jpg', 'IMG_7753.jpg': '16.jpg', 'IMG_7754.jpg': '17.jpg', 'IMG_7776.jpg': '18.jpg', 'IMG_7777.jpg': '19.jpg', 'IMG_7778.jpg': '20.jpg', 'IMG_7779.jpg': '21.jpg', 'IMG_7780.jpg': '22.jpg', 'IMG_7781.jpg': '23.jpg', 'IMG_7782.jpg': '24.jpg', 'IMG_7783.jpg': '25.jpg', 'IMG_7784.jpg': '26.jpg', 'IMG_7785.jpg': '27.jpg', 'IMG_7786.jpg': '28.jpg', 'IMG_7788.jpg': '29.jpg', 'IMG_7790.jpg': '30.jpg', 'IMG_7791.jpg': '31.jpg', 'IMG_7792.jpg': '32.jpg', 'IMG_7794.jpg': '33.jpg', 'IMG_7795.jpg': '34.jpg', 'IMG_7796.jpg': '35.jpg', 'IMG_7797.jpg': '36.jpg', 'IMG_7798.jpg': '37.jpg', 'IMG_7799.jpg': '38.jpg', 'IMG_7800.jpg': '39.jpg', 'IMG_7801.jpg': '40.jpg', 'IMG_7802.jpg': '41.jpg', 'IMG_7803.jpg': '42.jpg', 'IMG_7804.jpg': '43.jpg', 'IMG_7805.jpg': '44.jpg', 'IMG_7807.jpg': '45.jpg', 'IMG_7809.jpg': '46.jpg', 'IMG_7810.jpg': '47.jpg', 'IMG_7811.jpg': '48.jpg', 'IMG_7812.jpg': '49.jpg', 'IMG_7813.jpg': '50.jpg', 'IMG_7814.jpg': '51.jpg', 'IMG_7815.jpg': '52.jpg', 'IMG_7816.jpg': '53.jpg', 'IMG_7817.jpg': '54.jpg', 'IMG_7818.jpg': '55.jpg', 'IMG_7819.jpg': '56.jpg', 'IMG_7820.jpg': '57.jpg', 'IMG_7821.jpg': '58.jpg', 'IMG_7822.jpg': '59.jpg', 'IMG_7823.jpg': '60.jpg', 'IMG_7824.jpg': '61.jpg', 'IMG_7825.jpg': '62.jpg', 'IMG_7826.jpg': '63.jpg', 'IMG_7827.jpg': '64.jpg', 'IMG_7828.jpg': '65.jpg', 'IMG_7829.jpg': '66.jpg'}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -219,47 +252,76 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 34,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "error",
|
||||
"evalue": "OpenCV(4.5.4) ./modules/imgproc/src/resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function 'resize'\n",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31merror\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[1;32m/mnt/code/libraries/testprocessing.ipynb Cell 9\u001b[0m line \u001b[0;36m2\n\u001b[1;32m <a href='vscode-notebook-cell://attached-container%2B7b22636f6e7461696e65724e616d65223a222f72696c6962726172696573646576656e76227d/mnt/code/libraries/testprocessing.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0'>1</a>\u001b[0m img \u001b[39m=\u001b[39m cv2\u001b[39m.\u001b[39mimread(\u001b[39m'\u001b[39m\u001b[39m/mnt/dataset/baseimages/1.jpg\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[0;32m----> <a href='vscode-notebook-cell://attached-container%2B7b22636f6e7461696e65724e616d65223a222f72696c6962726172696573646576656e76227d/mnt/code/libraries/testprocessing.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=1'>2</a>\u001b[0m out \u001b[39m=\u001b[39m mf\u001b[39m.\u001b[39;49mhoughlineprocessing(img)\n",
|
||||
"File \u001b[0;32m/mnt/code/autocropper/myfunctions.py:1042\u001b[0m, in \u001b[0;36mhoughlineprocessing\u001b[0;34m(image)\u001b[0m\n\u001b[1;32m 1041\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mhoughlineprocessing\u001b[39m(image):\n\u001b[0;32m-> 1042\u001b[0m croppedanddeskewed, _ \u001b[39m=\u001b[39m houghlinedeskewandcrop(image)\n\u001b[1;32m 1043\u001b[0m \u001b[39m##IF IT DOESN'T CHANGE THE IMAGE (CHANGE THE _ TO SOMETHING USEFUL), THEN CROPCLARIFYING SHOULD JUST DO THE TEXT ISOLATION SECTION AND NOT TRY AND WHITE OUT ANY BACKGROUND.\u001b[39;00m\n\u001b[1;32m 1044\u001b[0m \u001b[39m## IF THERE'S NO CROPPING, MAYBE EVEN JUMP RIGHT TO USING THE EXTERNAL DESKEW FIRST BEFORE TOSSING IT INTO CROPCLARIFYING\u001b[39;00m\n\u001b[1;32m 1046\u001b[0m postprocessed \u001b[39m=\u001b[39m cropclarifying(croppedanddeskewed)\n",
|
||||
"File \u001b[0;32m/mnt/code/autocropper/myfunctions.py:452\u001b[0m, in \u001b[0;36mhoughlinedeskewandcrop\u001b[0;34m(image)\u001b[0m\n\u001b[1;32m 446\u001b[0m rotationangle \u001b[39m=\u001b[39m houghlinedeskewangle(dst1)\n\u001b[1;32m 448\u001b[0m \u001b[39m# -----------------end of finding angle to deskew-----------------\u001b[39;00m\n\u001b[1;32m 449\u001b[0m \n\u001b[1;32m 450\u001b[0m \u001b[39m## -----------------deskewing and then cropping-----------------\u001b[39;00m\n\u001b[0;32m--> 452\u001b[0m \u001b[39mreturn\u001b[39;00m houghlinedeskewthencrop(croppedogimage, dst1, rotationangle)\n",
|
||||
"File \u001b[0;32m/mnt/code/autocropper/myfunctions.py:420\u001b[0m, in \u001b[0;36mhoughlinedeskewthencrop\u001b[0;34m(baseimage, preppedimage, rotationangle)\u001b[0m\n\u001b[1;32m 414\u001b[0m scaledrect \u001b[39m=\u001b[39m (\u001b[39mint\u001b[39m(rect[\u001b[39m0\u001b[39m]\u001b[39m*\u001b[39msizemultiplier), \u001b[39mint\u001b[39m(rect[\u001b[39m1\u001b[39m]\u001b[39m*\u001b[39msizemultiplier), \u001b[39mint\u001b[39m(rect[\u001b[39m2\u001b[39m]\u001b[39m*\u001b[39msizemultiplier), \u001b[39mint\u001b[39m(rect[\u001b[39m3\u001b[39m]\u001b[39m*\u001b[39msizemultiplier))\n\u001b[1;32m 416\u001b[0m croppedbaseimage \u001b[39m=\u001b[39m rotatedbaseimage[scaledrect[\u001b[39m1\u001b[39m]:scaledrect[\u001b[39m3\u001b[39m], scaledrect[\u001b[39m0\u001b[39m]:scaledrect[\u001b[39m2\u001b[39m], :]\n\u001b[0;32m--> 420\u001b[0m shrunkencbi, sizemultiplier \u001b[39m=\u001b[39m ResizeWithAspectRatio(croppedbaseimage, width\u001b[39m=\u001b[39;49m\u001b[39m1000\u001b[39;49m, retscale\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m)\n\u001b[1;32m 421\u001b[0m gray \u001b[39m=\u001b[39m cv2\u001b[39m.\u001b[39mcvtColor(shrunkencbi, cv2\u001b[39m.\u001b[39mCOLOR_BGR2GRAY)\n\u001b[1;32m 422\u001b[0m thresh \u001b[39m=\u001b[39m cv2\u001b[39m.\u001b[39mthreshold(gray, \u001b[39m200\u001b[39m, \u001b[39m255\u001b[39m, cv2\u001b[39m.\u001b[39mTHRESH_BINARY)[\u001b[39m1\u001b[39m]\n",
|
||||
"File \u001b[0;32m/mnt/code/autocropper/myfunctions.py:27\u001b[0m, in \u001b[0;36mResizeWithAspectRatio\u001b[0;34m(image, width, height, inter, retscale)\u001b[0m\n\u001b[1;32m 23\u001b[0m dim \u001b[39m=\u001b[39m (width, \u001b[39mint\u001b[39m(h \u001b[39m*\u001b[39m r))\n\u001b[1;32m 25\u001b[0m \u001b[39mif\u001b[39;00m (retscale \u001b[39m==\u001b[39m \u001b[39mTrue\u001b[39;00m):\n\u001b[1;32m 26\u001b[0m \u001b[39m# print(\"hi\")\u001b[39;00m\n\u001b[0;32m---> 27\u001b[0m \u001b[39mreturn\u001b[39;00m (cv2\u001b[39m.\u001b[39;49mresize(image, dim, interpolation\u001b[39m=\u001b[39;49minter), \u001b[39m1\u001b[39m\u001b[39m/\u001b[39mr)\n\u001b[1;32m 28\u001b[0m \u001b[39mreturn\u001b[39;00m cv2\u001b[39m.\u001b[39mresize(image, dim, interpolation\u001b[39m=\u001b[39minter)\n",
|
||||
"\u001b[0;31merror\u001b[0m: OpenCV(4.5.4) ./modules/imgproc/src/resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function 'resize'\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"img = cv2.imread('/mnt/dataset/baseimages/1.jpg')\n",
|
||||
"out = mf.houghlineprocessing(img)\n",
|
||||
"# img = cv2.imread('/mnt/dataset/baseimages/1.jpg')\n",
|
||||
"# out = mf.houghlineprocessing(img)\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"showimgs(out)"
|
||||
"# showimgs(out)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/mnt/dataset/baseimages/0.jpg\n",
|
||||
"/mnt/dataset/baseimages/1.jpg\n",
|
||||
"/mnt/dataset/baseimages/10.jpg\n",
|
||||
"/mnt/dataset/baseimages/11.jpg\n",
|
||||
"/mnt/dataset/baseimages/12.jpg\n",
|
||||
"/mnt/dataset/baseimages/13.jpg\n",
|
||||
"/mnt/dataset/baseimages/14.jpg\n",
|
||||
"/mnt/dataset/baseimages/15.jpg\n",
|
||||
"/mnt/dataset/baseimages/16.jpg\n",
|
||||
"/mnt/dataset/baseimages/17.jpg\n",
|
||||
"/mnt/dataset/baseimages/18.jpg\n",
|
||||
"/mnt/dataset/baseimages/19.jpg\n",
|
||||
"/mnt/dataset/baseimages/2.jpg\n",
|
||||
"/mnt/dataset/baseimages/20.jpg\n",
|
||||
"/mnt/dataset/baseimages/21.jpg\n",
|
||||
"/mnt/dataset/baseimages/22.jpg\n",
|
||||
"/mnt/dataset/baseimages/23.jpg\n",
|
||||
"/mnt/dataset/baseimages/24.jpg\n",
|
||||
"/mnt/dataset/baseimages/25.jpg\n",
|
||||
"/mnt/dataset/baseimages/26.jpg\n",
|
||||
"/mnt/dataset/baseimages/27.jpg\n",
|
||||
"/mnt/dataset/baseimages/28.jpg\n",
|
||||
"/mnt/dataset/baseimages/29.jpg\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ename": "TypeError",
|
||||
"evalue": "object of type 'NoneType' has no len()",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[1;32m/mnt/code/libraries/testprocessing.ipynb Cell 12\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> <a href='vscode-notebook-cell://attached-container%2B7b22636f6e7461696e65724e616d65223a222f72696c6962726172696573646576656e76227d/mnt/code/libraries/testprocessing.ipynb#X14sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0'>1</a>\u001b[0m autocrop(\u001b[39m\"\u001b[39;49m\u001b[39m/mnt/dataset/\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n",
|
||||
"\u001b[1;32m/mnt/code/libraries/testprocessing.ipynb Cell 12\u001b[0m line \u001b[0;36m2\n\u001b[1;32m <a href='vscode-notebook-cell://attached-container%2B7b22636f6e7461696e65724e616d65223a222f72696c6962726172696573646576656e76227d/mnt/code/libraries/testprocessing.ipynb#X14sdnNjb2RlLXJlbW90ZQ%3D%3D?line=19'>20</a>\u001b[0m \u001b[39m# print(img)\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell://attached-container%2B7b22636f6e7461696e65724e616d65223a222f72696c6962726172696573646576656e76227d/mnt/code/libraries/testprocessing.ipynb#X14sdnNjb2RlLXJlbW90ZQ%3D%3D?line=20'>21</a>\u001b[0m t1 \u001b[39m=\u001b[39m time\u001b[39m.\u001b[39mtime()\n\u001b[0;32m---> <a href='vscode-notebook-cell://attached-container%2B7b22636f6e7461696e65724e616d65223a222f72696c6962726172696573646576656e76227d/mnt/code/libraries/testprocessing.ipynb#X14sdnNjb2RlLXJlbW90ZQ%3D%3D?line=21'>22</a>\u001b[0m autocropped \u001b[39m=\u001b[39m mf\u001b[39m.\u001b[39;49mhoughlineprocessing(img)\n\u001b[1;32m <a href='vscode-notebook-cell://attached-container%2B7b22636f6e7461696e65724e616d65223a222f72696c6962726172696573646576656e76227d/mnt/code/libraries/testprocessing.ipynb#X14sdnNjb2RlLXJlbW90ZQ%3D%3D?line=22'>23</a>\u001b[0m tdiffs\u001b[39m.\u001b[39mappend(time\u001b[39m.\u001b[39mtime() \u001b[39m-\u001b[39m t1)\n\u001b[1;32m <a href='vscode-notebook-cell://attached-container%2B7b22636f6e7461696e65724e616d65223a222f72696c6962726172696573646576656e76227d/mnt/code/libraries/testprocessing.ipynb#X14sdnNjb2RlLXJlbW90ZQ%3D%3D?line=23'>24</a>\u001b[0m cv2\u001b[39m.\u001b[39mimwrite(datasetpath\u001b[39m+\u001b[39msubpathtoaugmentedfiles\u001b[39m+\u001b[39mfilename, autocropped)\n",
|
||||
"File \u001b[0;32m/mnt/code/autocropper/myfunctions.py:1152\u001b[0m, in \u001b[0;36mhoughlineprocessing\u001b[0;34m(image)\u001b[0m\n\u001b[1;32m 1151\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mhoughlineprocessing\u001b[39m(image):\n\u001b[0;32m-> 1152\u001b[0m croppedanddeskewed, angle \u001b[39m=\u001b[39m houghlinedeskewandcrop(image)\n\u001b[1;32m 1153\u001b[0m \u001b[39m# return croppedanddeskewed\u001b[39;00m\n\u001b[1;32m 1154\u001b[0m \n\u001b[1;32m 1155\u001b[0m \n\u001b[1;32m 1156\u001b[0m \u001b[39m# postprocessed = cropclarifying(croppedanddeskewed)\u001b[39;00m\n\u001b[1;32m 1157\u001b[0m postprocessed \u001b[39m=\u001b[39m croppedanddeskewed\n",
|
||||
"File \u001b[0;32m/mnt/code/autocropper/myfunctions.py:509\u001b[0m, in \u001b[0;36mhoughlinedeskewandcrop\u001b[0;34m(image)\u001b[0m\n\u001b[1;32m 503\u001b[0m croppedcanny, croppedimage, canny, ogimage, rect \u001b[39m=\u001b[39m prepimageforhoughline(image, returnrect\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m) \u001b[39m## scaling and cropping occurs. need to also return the changes done\u001b[39;00m\n\u001b[1;32m 504\u001b[0m \u001b[39m# return canny, ogimage\u001b[39;00m\n\u001b[1;32m 505\u001b[0m \u001b[39m# print(canny.shape)\u001b[39;00m\n\u001b[1;32m 506\u001b[0m \u001b[39m# print(croppedogimage.shape)\u001b[39;00m\n\u001b[1;32m 507\u001b[0m \n\u001b[1;32m 508\u001b[0m \u001b[39m## -----------------finding angle to deskew-----------------\u001b[39;00m\n\u001b[0;32m--> 509\u001b[0m rotationangle \u001b[39m=\u001b[39m houghlinedeskewangle(croppedcanny)\n\u001b[1;32m 510\u001b[0m \u001b[39m# print(croppedcanny.shape)\u001b[39;00m\n\u001b[1;32m 511\u001b[0m \u001b[39m# print(abs(rotationangle))\u001b[39;00m\n\u001b[1;32m 512\u001b[0m \u001b[39mif\u001b[39;00m (croppedcanny\u001b[39m.\u001b[39mshape[\u001b[39m0\u001b[39m] \u001b[39m>\u001b[39m croppedcanny\u001b[39m.\u001b[39mshape[\u001b[39m1\u001b[39m]):\n",
|
||||
"File \u001b[0;32m/mnt/code/autocropper/myfunctions.py:383\u001b[0m, in \u001b[0;36mhoughlinedeskewangle\u001b[0;34m(image)\u001b[0m\n\u001b[1;32m 381\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mhoughlinedeskewangle\u001b[39m(image):\n\u001b[1;32m 382\u001b[0m lines \u001b[39m=\u001b[39m cv2\u001b[39m.\u001b[39mHoughLines(image, \u001b[39m1\u001b[39m, np\u001b[39m.\u001b[39mpi\u001b[39m/\u001b[39m\u001b[39m180\u001b[39m, \u001b[39mint\u001b[39m(\u001b[39mmax\u001b[39m(image\u001b[39m.\u001b[39mshape[\u001b[39m0\u001b[39m], image\u001b[39m.\u001b[39mshape[\u001b[39m1\u001b[39m])\u001b[39m/\u001b[39m\u001b[39m6\u001b[39m), \u001b[39mNone\u001b[39;00m, \u001b[39m0\u001b[39m, \u001b[39m0\u001b[39m)\n\u001b[0;32m--> 383\u001b[0m angles \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39mzeros(\u001b[39mlen\u001b[39;49m(lines))\n\u001b[1;32m 384\u001b[0m \u001b[39mif\u001b[39;00m lines \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 385\u001b[0m \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(\u001b[39m0\u001b[39m, \u001b[39mlen\u001b[39m(lines)):\n",
|
||||
"\u001b[0;31mTypeError\u001b[0m: object of type 'NoneType' has no len()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# autocrop(\"/mnt/dataset/\")"
|
||||
"autocrop(\"/mnt/dataset/\")"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user