This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_pdf( | |
pdf_path: str | os.PathLike, | |
img_dir: str | os.PathLike, | |
text_output_path: str | os.PathLike, | |
skip_first_image: bool = True, | |
) -> None: | |
""" | |
Extracts text and images from a PDF file. | |
This function extracts text from each page of the PDF and saves it to a text file. | |
It also extracts images from each page and saves them in a specified directory. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import numpy.typing as npt | |
def generate_sine_wave(time_steps: npt.NDArray, amp: float, freq: float) -> npt.NDArray: | |
"""Generate a sine wave signal with given amplitude and frequency. | |
Args: | |
time_steps (npt.NDArray): _Time steps in the form of an 1D array_ | |
amp (float): _Amplitude of the sine wave_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0.000000E+00 9.189000 | |
2.000000E-03 9.189000 | |
4.000000E-03 9.189000 | |
6.000000E-03 9.189000 | |
8.000000E-03 9.189000 | |
1.000000E-02 9.189000 | |
1.200000E-02 9.189000 | |
1.400000E-02 9.189000 | |
1.600000E-02 9.189000 | |
1.800000E-02 9.189000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
import imageio.v3 as iio | |
from pygifsicle import optimize | |
im = iio.imread( | |
'https://github.com/yuchen-xue/Spring-MySQL-TF-Detection/raw/master/asset/demo.gif', index=None) | |
stacked_frames = np.stack([ | |
cv2.resize(frame, (640, 360), interpolation=cv2.INTER_AREA) for frame in im | |
], axis=0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from pathlib import Path | |
import cv2 | |
import numpy.typing as npt | |
def resize_white_fill(img: npt.NDArray, w_target: int, h_target: int) -> npt.NDArray: | |
"""Resize an image to a target width and height, while keeping the original | |
height-width ratio. If the original height-width ratio is different from |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
WHITE = (255, 255, 255) | |
def dup_img_9( | |
file_in: str, file_out: str, pad_horizontal: int = 10, pad_vertical: int = 10 | |
): | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /// script | |
# requires-python = ">=3.4" | |
# dependencies = [ | |
# "opencv-python", | |
# ] | |
# /// | |
from pathlib import Path | |
import cv2 | |
import numpy as np |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
# Dockerfile for building an image with non-root privilege as default | |
# In addition, it's capable of displaying images created by | |
# `cv2.imshow()` and `plt.show()` | |
# In order to use the full functionality, one should | |
# | |
# 1. Run the command `xhost +local:docker` | |
# | |
# 2. build an image by including |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ref: | |
# https://github.com/Valian/docker-python-opencv-ffmpeg/blob/master/Dockerfile-py3-cuda | |
ARG CUDA_VERSION="10.0" | |
ARG FLAVOR="runtime" | |
FROM nvidia/cuda:${CUDA_VERSION}-cudnn7-${FLAVOR}-ubuntu16.04 | |
ARG OPENCV_VERSION="4.1.0" | |
# Install all dependencies for OpenCV | |
RUN apt-get -y update && \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mymodule | |
print(mymodule.__doc__) | |
print(mymodule.f.__doc__) |
NewerOlder