MCPcopy Create free account
hub / github.com/DeepLabCut/DeepLabCut / FrameCropper

Class FrameCropper

deeplabcut/gui/widgets.py:469–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

467
468
469class FrameCropper(QtWidgets.QDialog):
470 def __init__(self, video, parent=None):
471 super().__init__(parent)
472 self.clip = VideoWriter(video)
473
474 self.fig = Figure()
475 self.ax = self.fig.add_subplot(111)
476 self.ax_help = self.fig.add_axes([0.9, 0.2, 0.1, 0.1])
477 self.ax_save = self.fig.add_axes([0.9, 0.1, 0.1, 0.1])
478 self.crop_button = Button(self.ax_save, "Crop")
479 self.crop_button.on_clicked(self.validate_crop)
480 self.help_button = Button(self.ax_help, "Help")
481 self.help_button.on_clicked(self.display_help)
482
483 self.canvas = FigureCanvas(self.fig)
484 layout = QtWidgets.QVBoxLayout(self)
485 layout.addWidget(self.canvas)
486 self.setLayout(layout)
487
488 self.bbox = [0, 0, 0, 0]
489
490 def draw_bbox(self):
491 frame = None
492 # Read the video until a frame is successfully read
493 while frame is None:
494 frame = self.clip.read_frame()
495 self.bbox[-2:] = frame.shape[1], frame.shape[0]
496 self.ax.imshow(frame[:, :, ::-1])
497
498 self.rs = RectangleSelector(
499 self.ax,
500 self.line_select_callback,
501 minspanx=5,
502 minspany=5,
503 interactive=True,
504 spancoords="pixels",
505 )
506 self.show()
507 self.fig.canvas.start_event_loop(timeout=-1)
508 return self.bbox
509
510 def line_select_callback(self, eclick, erelease):
511 self.bbox[:2] = int(eclick.xdata), int(eclick.ydata) # x1, y1
512 self.bbox[2:] = int(erelease.xdata), int(erelease.ydata) # x2, y2
513
514 def validate_crop(self, *args):
515 self.fig.canvas.stop_event_loop()
516 self.close()
517
518 def display_help(self, *args):
519 print(
520 "1. Use left click to select the region of interest. A red box will be drawn around the selected region."
521 "\n\n2. Use the corner points to expand the box and center to move the box around the image. \n\n3. Click"
522 )
523
524
525class SkeletonBuilder(QtWidgets.QDialog, BaseSkeletonBuilder):

Callers 2

select_cropping_areaFunction · 0.90
_crop_videoFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected