- grassloper now uses improtools to debug image processing
- the user can now change grassloper's parameters using command line arguments
This commit is contained in:
parent
3fa3a0afab
commit
0d41944c2a
10
README.md
10
README.md
|
@ -18,5 +18,13 @@ bob@stykades:~/work/grassloper$ source ./grassloper.venv/bin/activate
|
|||
# this automatically installs the packages that grassloper depends on
|
||||
(grassloper.venv) bob@stykades:~/work/grassloper$ pip install -e ./grassloper.git
|
||||
# now that grassloper is installed in grassloper.venv and grassloper.venv is activated, simply run it using its command line 'grassloper'
|
||||
(grassloper.venv) bob@stykades:~/work/grassloper$ grassloper
|
||||
(grassloper.venv) bob@stykades:~/work/grassloper$ grassloper --help
|
||||
```
|
||||
|
||||
# how to use
|
||||
|
||||
`grassloper`'s usage is described with the `--help` command line argument:
|
||||
|
||||
```sh
|
||||
(grassloper.venv) bob@stykades:~/work/grassloper$ grassloper --help
|
||||
```
|
||||
|
|
|
@ -6,6 +6,8 @@ import math
|
|||
import h5py
|
||||
import time
|
||||
import scipy.stats
|
||||
import argparse
|
||||
from improtools.imageprocessing import ImageProcessDebugger, IMovieProcessListener, NullMovieProcessListener, MovieProcessDebugger
|
||||
|
||||
|
||||
def create_slope_image(image_width: int, image_height: int, p1_angle: float, p1_radius: float, bg_color: float = 0.0, fg_color: float = 1.0):
|
||||
|
@ -91,8 +93,10 @@ class SlopeFinder():
|
|||
def __init__(self, beads_radius: float):
|
||||
self.beads_radius = beads_radius
|
||||
|
||||
def find_slope(self, trac_data: TracData, frame_index: int):
|
||||
def find_slope(self, trac_data: TracData, frame_index: int, mo_pro_listener: IMovieProcessListener = NullMovieProcessListener()):
|
||||
isbead_image = SlopeFinder.create_isbead_image(trac_data, frame_index, self.beads_radius)
|
||||
mo_pro_listener.onImage(isbead_image, 'isbead')
|
||||
mo_pro_listener.onBaseImage(isbead_image, 'isbead')
|
||||
cv2.imwrite('isbead_%04d.tif' % frame_index, isbead_image)
|
||||
if False:
|
||||
kernel = np.ones((15, 15), np.uint8)
|
||||
|
@ -138,6 +142,11 @@ class SlopeFinder():
|
|||
y = [pt[1] for pt in surface_pts]
|
||||
lin_regress_result = scipy.stats.linregress(x, y)
|
||||
print(lin_regress_result)
|
||||
from_vertex = [0.0, lin_regress_result.intercept]
|
||||
x_max = float(isbead_image.shape[1])
|
||||
to_vertex = [x_max, lin_regress_result.intercept + x_max * lin_regress_result.slope]
|
||||
mo_pro_listener.m_imageProcessListener.onLine( ((from_vertex[0], from_vertex[1]), (to_vertex[0], to_vertex[1])), 'slope')
|
||||
|
||||
|
||||
@staticmethod
|
||||
def create_isbead_image(trac_data: TracData, frame_index: int, particle_radius: float):
|
||||
|
@ -153,11 +162,23 @@ class SlopeFinder():
|
|||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser('grassloper', description='estimates the slope of granular surface', epilog='example: \n\tgrassloper --part-pos-file=./grassloper.git/samples/TracTrac/sample002_track.hdf5 --particle-radius=11.0 --debug-dir=\'./improdebug\'')
|
||||
parser.add_argument('--part-pos-file', type=Path, default=None, required=True, help='the input file containing the particle positions')
|
||||
parser.add_argument('--part-pos-file-format', type=str, choices=['tractrac-hdf5'], default='tractrac-hdf5', help='the file format of the input file that contains particle positions')
|
||||
parser.add_argument('--particle-radius', type=float, required=True, help='the radius of the particles in pixels', default=11)
|
||||
parser.add_argument('--debug-dir', type=Path, default=None, help='where to store image processing debug files')
|
||||
args = parser.parse_args()
|
||||
# python3 ./tractrac.git/Python/tractrac.py -f ./grassloper.git/samples/sample002.avi --output 1 -a --saveplot
|
||||
trac_data = hdf5_to_trac_data('./grassloper.git/samples/TracTrac/sample002_track.hdf5')
|
||||
slope_finder = SlopeFinder(beads_radius=11.0)
|
||||
for frame_index in range(1, 2):
|
||||
slope_finder.find_slope(trac_data, frame_index=frame_index)
|
||||
if args.debug_dir is not None:
|
||||
mo_pro_listener = MovieProcessDebugger(args.debug_dir)
|
||||
else:
|
||||
mo_pro_listener = NullMovieProcessListener()
|
||||
trac_data = hdf5_to_trac_data(args.part_pos_file)
|
||||
slope_finder = SlopeFinder(beads_radius=args.particle_radius)
|
||||
for frame_index in range(1, 3):
|
||||
mo_pro_listener.onImageProcessingStart()
|
||||
slope_finder.find_slope(trac_data, frame_index=frame_index, mo_pro_listener=mo_pro_listener)
|
||||
mo_pro_listener.onImageProcessingEnd()
|
||||
|
||||
# slope_image = create_slope_image(image_width=128, image_height=256, p1_angle=0.7, p1_radius=3.0)
|
||||
# cv2.imwrite(str(Path('toto.tif')), slope_image)
|
||||
|
|
Loading…
Reference in New Issue