Small update : after trial and error I managed to find something that
appears to work! Multiple ROIs for multiple scenes are constructed
using :
roi = pg.RectROI([0, 0], [50, 50], pen=(0, 9))
roi.addScaleRotateHandle([1, 0], [1, 1])
roi.addScaleHandle([0, 0], [1, 1])
roi.sigRegionChanged.connect(self._roi_update)
Then, the positions is updated when the user moves the first ROI (in
self._roi_update) with :
# ...after getting the handles' positions from the updated ROI
ht = [np.array([h.x(), h.y(), 0.]) for h in hh]
# The new ROI position is the position of that handle
new_position = QtCore.QPointF(float(hh[2][0]), float(ht[2][1]))
# Its new size is defined by the handles as well
new_size = QtCore.QSizeF(
float(np.linalg.norm(ht[2] - ht[1])),
float(np.linalg.norm(ht[1] - ht[0]))
)
# The new rotation is the angle between the vector defined between
# the first and second handles, and the vertical axis.
# I lazily stole angle_between from
http://stackoverflow.com/questions/2827393.
new_rotation = angle_between(ht[1] - ht[0], np.array([0., 1., 0.]))
new_rotation = 180 * new_rotation / 3.1415926524 - 180.
# Set them
roi.setPos(new_position, update=False, finish=False)
roi.setSize(new_size, update=False, finish=False)
roi.setAngle(new_rotation, update=False, finish=False)
With this I have linked ROIs : when I move one ROI in one camera
frame, the other ROIs move as well.
The complete program also involves an homography that is computed in
the background to let the user select matching regions in multiple
images taken by a multi-frame camera mounted on a rigid support. And
that in about 3 or 4 hours of work, including the UI. PyQtGraph is
pretty neat! ;)
Cheers,
François-Xavier