Skip to content

Commit f54f098

Browse files
committed
removed blob_detection
1 parent 86d202d commit f54f098

2 files changed

Lines changed: 35 additions & 67 deletions

File tree

openptv_python/epi.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Epipolar geometry."""
2-
from dataclasses import dataclass, field
3-
from typing import List
2+
from typing import List, Tuple
43

54
import numpy as np
5+
from numba import float64, int32, njit
6+
from numba.experimental import jitclass
67

78
from .calibration import Calibration
89
from .constants import PT_UNUSED
@@ -12,8 +13,13 @@
1213
from .ray_tracing import ray_tracing
1314
from .trafo import dist_to_flat, metric_to_pixel, pixel_to_metric
1415

16+
spec = [
17+
('pnr', int32),
18+
('tol', float64),
19+
('corr', float64),
20+
]
1521

16-
@dataclass
22+
@jitclass(spec)
1723
class Candidate:
1824
"""Candidate point in the second image."""
1925

@@ -22,10 +28,16 @@ def __init__(self, pnr=PT_UNUSED, tol=0.0, corr=0.0):
2228
self.tol = tol
2329
self.corr = corr
2430

25-
def __repr__(self):
26-
return f"Candidate(pnr={self.pnr}, tol={self.tol}, corr={self.corr})"
31+
# def __repr__(self):
32+
# return f"Candidate(pnr={self.pnr}, tol={self.tol}, corr={self.corr})"
2733

34+
spec = [
35+
('pnr', int32),
36+
('x', float64),
37+
('y', float64),
38+
]
2839

40+
@jitclass(spec)
2941
class Coord2d:
3042
"""2D coordinates in the image space."""
3143

@@ -34,31 +46,38 @@ def __init__(self, pnr=PT_UNUSED, x=0.0, y=0.0):
3446
self.x = x
3547
self.y = y
3648

37-
def __repr__(self):
38-
return f"Coord2d(pnr={self.pnr}, x={self.x}, y={self.y})"
39-
49+
# def __repr__(self):
50+
# return f"Coord2d(pnr={self.pnr}, x={self.x}, y={self.y})"
4051

52+
@njit
4153
def sort_coord2d_x(crd: List[Coord2d]) -> List[Coord2d]:
4254
"""Quicksort for coordinates by x ."""
4355
return sorted(crd, key=lambda p: p.x)
4456

45-
57+
@njit
4658
def sort_coord2d_y(crd: List[Coord2d]) -> List[Coord2d]:
4759
"""Sort coordinates by y."""
4860
return sorted(crd, key=lambda p: p.y)
4961

62+
spec = [
63+
('pnr', int32),
64+
('x', float64),
65+
('y', float64),
66+
('z', float64),
67+
]
5068

51-
@dataclass
69+
@jitclass(spec)
5270
class Coord3d:
53-
"""3D coordinates in the object space."""
71+
"""2D coordinates in the image space."""
5472

55-
pnr: int = field(default=PT_UNUSED)
56-
x: float = field(default=0.0)
57-
y: float = field(default=0.0)
58-
z: float = field(default=0.0)
73+
def __init__(self, pnr=PT_UNUSED, x=0.0, y=0.0, z=0.0):
74+
self.pnr = pnr
75+
self.x = x
76+
self.y = y
77+
self.z = z
5978

6079

61-
def epi_mm(xl, yl, cal1, cal2, mmp, vpar) -> tuple[float, float, float, float]:
80+
def epi_mm(xl, yl, cal1, cal2, mmp, vpar) -> Tuple[float, float, float, float]:
6281
"""Return the end points of the epipolar line in the "second" camera.
6382
6483
/* epi_mm() takes a point in images space of one camera, positions of this

openptv_python/segmentation.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -614,54 +614,3 @@ def target_recognition(
614614
target_array = targ_rec(img, tpar, xmin, xmax, ymin, ymax, cparam, cam)
615615

616616
return target_array
617-
618-
619-
def blob_detection(image, threshold) -> List[int]:
620-
"""Detect blobs in an image."""
621-
# Initialize the output list.
622-
blobs = []
623-
624-
# Convert the image to grayscale.
625-
grayscale_image = np.array(image).mean(axis=2)
626-
627-
# Find all of the pixels in the image that are above the threshold.
628-
above_threshold_pixels = np.where(grayscale_image > threshold)[0]
629-
630-
# Create a queue to store the pixels that are currently being processed.
631-
waitlist = []
632-
633-
# Add the first pixel to the queue.
634-
waitlist.append(above_threshold_pixels[0])
635-
636-
# While the queue is not empty:
637-
while waitlist:
638-
# Pop the first pixel from the queue.
639-
pixel = waitlist.pop(0)
640-
641-
# Get the x- and y-coordinates of the pixel.
642-
x = pixel % image.shape[1]
643-
y = pixel // image.shape[1]
644-
645-
# Check to see if the pixel is within the bounds of the image.
646-
if x < 0 or x >= image.shape[1] or y < 0 or y >= image.shape[0]:
647-
continue
648-
649-
# Check to see if the pixel is already part of a blob.
650-
if pixel in blobs:
651-
continue
652-
653-
# Add the pixel to the current blob.
654-
blobs.append(pixel)
655-
656-
# Add all of the neighboring pixels that are above the threshold to the queue.
657-
for neighbor in [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)]:
658-
if (
659-
neighbor[0] >= 0
660-
and neighbor[0] < image.shape[1]
661-
and neighbor[1] >= 0
662-
and neighbor[1] < image.shape[0]
663-
and grayscale_image[neighbor] > threshold
664-
):
665-
waitlist.append(neighbor)
666-
667-
return blobs

0 commit comments

Comments
 (0)