Skip to content

Commit

Permalink
video works
Browse files Browse the repository at this point in the history
  • Loading branch information
karan316 committed Jul 8, 2022
1 parent 9b21fe6 commit 9768c00
Showing 1 changed file with 32 additions and 41 deletions.
73 changes: 32 additions & 41 deletions document-scanner.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -18,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -35,7 +35,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -67,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -80,7 +80,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -90,7 +90,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -116,7 +116,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -140,7 +140,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -218,7 +218,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -246,7 +246,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -290,7 +290,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -327,36 +327,24 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"number of lines: 5\n",
"all corners found: 7 [(553.2533333333333, 325.74666666666667), (605.8792383667651, 325.0542205478057), (64.61719438254651, 332.17608954759805), (605.8309155042759, 324.94132076908113), (64.27203028787278, 333.236533452921), (493.29920320553015, 62.026320216556805), (148.9762239307873, 73.0007578030028)]\n",
"------------------------------------------------------\n",
"final corners found: 4 [(553.2533333333333, 325.74666666666667), (64.61719438254651, 332.17608954759805), (493.29920320553015, 62.026320216556805), (148.9762239307873, 73.0007578030028)]\n",
"FINAL CORNERS: [(553.2533333333333, 325.74666666666667), (64.61719438254651, 332.17608954759805), (493.29920320553015, 62.026320216556805), (148.9762239307873, 73.0007578030028)]\n"
]
}
],
"outputs": [],
"source": [
"rng.seed(12345)\n",
"# rng.seed(12345)\n",
"\n",
"# read and show the input image\n",
"img_path = 'images/document-aligned.jpeg'\n",
"input_img = cv2.imread(img_path)\n",
"warped_img = scan_document(input_img)\n",
"# # read and show the input image\n",
"# img_path = 'images/document-aligned.jpeg'\n",
"# input_img = cv2.imread(img_path)\n",
"# warped_img = scan_document(input_img)\n",
"\n",
"cv2.imshow(\"Corners\", input_img)\n",
"# cv2.imshow(\"Corners\", input_img)\n",
"\n",
"if warped_img is not None: \n",
" cv2.imshow(\"Transformation\", warped_img)\n",
"# if warped_img is not None: \n",
"# cv2.imshow(\"Transformation\", warped_img)\n",
"\n",
"cv2.waitKey(10)\n",
"cv2.destroyAllWindows()\n"
"# cv2.waitKey(10)\n",
"# cv2.destroyAllWindows()\n"
]
},
{
Expand All @@ -365,7 +353,7 @@
"metadata": {},
"outputs": [],
"source": [
"video = cv2.VideoCapture('sample.mp4')\n",
"video = cv2.VideoCapture('videos/document-video-compress.mp4')\n",
" \n",
" \n",
"# Loop until the end of the video\n",
Expand All @@ -378,24 +366,27 @@
" \n",
" # Display the resulting frame\n",
" cv2.imshow('Video', frame)\n",
"\n",
" warped_img = scan_document(frame)\n",
" if warped_img is not None: \n",
" cv2.imshow(\"Warp\", warped_img)\n",
" \n",
" # conversion of BGR to grayscale is necessary to apply this operation\n",
" # gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n",
" gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n",
" \n",
" # # adaptive thresholding to use different threshold\n",
" # # values on different regions of the frame.\n",
" # Thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,\n",
" # cv2.THRESH_BINARY_INV, 11, 2)\n",
" # Thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 11, 2)\n",
" \n",
" # cv2.imshow('Thresh', Thresh)\n",
" # cv2.imshow('Threxsh', Thresh)\n",
" # define q as the exit button\n",
" if cv2.waitKey(25) & 0xFF == ord('q'):\n",
" break\n",
" \n",
"# release the video capture object\n",
"video.release()\n",
"# Closes all the windows currently opened.\n",
"cv2.destroyAllWindows()"
"# cv2.destroyAllWindows()"
]
}
],
Expand Down

0 comments on commit 9768c00

Please sign in to comment.