<jupyter_start><jupyter_text>Clone repo and install dependencies<jupyter_code>! if cd document-scanner-opencv-ws; then git pull; else git clone https://github.com/jiahuei/document-scanner-opencv-ws; fi
% cd document-scanner-opencv-ws<jupyter_output>/bin/bash: line 0: cd: document-scanner-opencv-ws: No such file or directory
Cloning into 'document-scanner-opencv-ws'...
remote: Enumerating objects: 88, done.[K
remote: Counting objects: 100% (88/88), done.[K
remote: Compressing objects: 100% (55/55), done.[K
remote: Total 88 (delta 32), reused 72 (delta 22), pack-reused 0[K
Unpacking objects: 100% (88/88), done.
/content/document-scanner-opencv-ws<jupyter_text>Remove `Pillow`, `matplotlib` and `numpy` from `requirements.txt`, since installing them require runtime restart.<jupyter_code>! sed -i '/^Pillow/d' requirements.txt
! sed -i '/^matplotlib/d' requirements.txt
! sed -i '/^numpy/d' requirements.txt
! pip install -r requirements.txt<jupyter_output>Collecting cmake~=3.18.4
[?25l  Downloading https://files.pythonhosted.org/packages/bb/c5/9a07d851bf8356dba2871f141f3e5e8d390995687be20316041a1e564d4c/cmake-3.18.4.post1-py3-none-manylinux1_x86_64.whl (17.7MB)
[K     |████████████████████████████████| 17.7MB 215kB/s 
[?25hRequirement already satisfied: imutils~=0.5.4 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 4)) (0.5.4)
Collecting opencv-contrib-python~=4.5.1.48
[?25l  Downloading https://files.pythonhosted.org/packages/17/69/cc755e763f4bb20cb25c7696172e6bb556719faf458c5362f4e54d6cd765/opencv_contrib_python-4.5.1.48-cp37-cp37m-manylinux2014_x86_64.whl (56.3MB)
[K     |████████████████████████████████| 56.4MB 76kB/s 
[?25hCollecting opencv-python~=4.5.1.48
[?25l  Downloading https://files.pythonhosted.org/packages/0f/13/192104516c4a3d92dc6b5e106ffcfbf0fe35f3c4faa49650205ff652af72/opencv_python-4.5.1.48-cp37-cp37m-manylinux2014_x86_64.whl (50.4MB)
[K     |████████████████████████████████| 50.4MB 66[...]<jupyter_text>Demo<jupyter_code>import os
from matplotlib import pyplot as plt
from IPython.display import Image
from scanner.detect_doc import A4Detector, visualise_detection
from scanner.utils.image import read_image
def plt_imshow(img, **kwargs):
    if img.ndim == 3:
        # opencv loads image as BGR
        img = img[..., ::-1]
    plt.imshow(img, **kwargs)<jupyter_output><empty_output><jupyter_text>Create the detector instance<jupyter_code>doc_detector = A4Detector(
    use_image_features=bool(os.getenv("DET_SIFT_FEATURE", False)),
    doc_extract_width=int(os.getenv("DOC_EXTRACT_WIDTH", 1414)),
    doc_extract_height=int(os.getenv("DOC_EXTRACT_HEIGHT", 2000)),
)<jupyter_output><empty_output><jupyter_text>Read the test image<jupyter_code>image = read_image(os.path.join("tests", "data", "test_w8_ben.jpg"))
plt_imshow(image)
res = doc_detector(image)<jupyter_output><empty_output><jupyter_text>Image after Otsu thresholding<jupyter_code>plt_imshow(res["debug"]["doc_vis"], cmap="gray")<jupyter_output><empty_output><jupyter_text>Output<jupyter_code>plt_imshow(res["doc"], cmap="gray")<jupyter_output><empty_output><jupyter_text>Corner points of the document<jupyter_code>res["doc_points"]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16682257561584035, 'fraction_numerical': 0.08543810414717805, 'mean_word_length': 6.693045563549161, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '111040', 'license': 'MIT', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1294, 'n_words': 195, 'path': 'demo.ipynb', 'repo_name': 'jiahuei/document-scanner-opencv-ws', 'size': '3207'}