-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: moving code into their own modules
- Loading branch information
Showing
4 changed files
with
116 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# helper function for plotting. | ||
|
||
import typing as T | ||
from pathlib import Path | ||
import matplotlib.pyplot as plt | ||
import cv2 as cv | ||
import numpy as np | ||
from loguru import logger | ||
|
||
from plotdigitizer import common | ||
|
||
|
||
def show_frame(img, msg="MSG: "): | ||
msgImg = np.zeros(shape=(50, img.shape[1])) | ||
cv.putText(msgImg, msg, (1, 40), 0, 0.5, 255) | ||
newImg = np.vstack((img, msgImg.astype(np.uint8))) | ||
cv.imshow(common.WindowName_, newImg) | ||
|
||
|
||
def plot_traj(traj, img, outfile: T.Optional[Path] = None): | ||
global locations_ | ||
import matplotlib.pyplot as plt | ||
|
||
x, y = zip(*traj) | ||
plt.figure() | ||
plt.subplot(211) | ||
|
||
for p in common.locations_: | ||
csize = img.shape[0] // 40 | ||
cv.circle( | ||
img, | ||
(int(p.x), int(img.shape[0] - p.y)), | ||
int(csize), | ||
(128, 128, 128), | ||
-1, | ||
) | ||
|
||
plt.imshow(img, interpolation="none", cmap="gray") | ||
plt.axis(False) | ||
plt.title("Original") | ||
plt.subplot(212) | ||
plt.title("Reconstructed") | ||
plt.plot(x, y) | ||
plt.tight_layout() | ||
if not str(outfile): | ||
plt.show() | ||
else: | ||
plt.savefig(outfile) | ||
logger.info(f"Saved to {outfile}") | ||
plt.close() |
This file contains 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