Keep track of number of rectangles drawn over an image using Mouse Events
-
Thanks for the reply!
So, the problem is as follows:When the image is opened in the GUI, the program checks whether there is an annotation file (which contains shapes information) with the same name and then opens it with the image, thus, we can see the shapes with the image in the GUI. Now as you know that I have a button that changes the brightness even though new shapes are drawn. (We discussed this previously and the issue was just the save directory).
Now, when the shapes are loaded from the file and I move them and try to change the brightness by pushing a button, the program checks the annotation file in the directory and loads it. Therefore, the previous shapes are loaded again. I want it to keep the same shape (when the shape is moved). Therefore I thought, if I can save the shapes when they are moved, this might eliminate the problem. I mean, I don't know if there is another method with which this can be solved but that was just what I came up with.
-
Thanks for the reply!
So, the problem is as follows:When the image is opened in the GUI, the program checks whether there is an annotation file (which contains shapes information) with the same name and then opens it with the image, thus, we can see the shapes with the image in the GUI. Now as you know that I have a button that changes the brightness even though new shapes are drawn. (We discussed this previously and the issue was just the save directory).
Now, when the shapes are loaded from the file and I move them and try to change the brightness by pushing a button, the program checks the annotation file in the directory and loads it. Therefore, the previous shapes are loaded again. I want it to keep the same shape (when the shape is moved). Therefore I thought, if I can save the shapes when they are moved, this might eliminate the problem. I mean, I don't know if there is another method with which this can be solved but that was just what I came up with.
Hi
Well could you not just change code so even if you change brightness,
it won't reload the shapes?Like adding a parameter to the function, so when called from the button,
it wont reload file but in all other case it will. -
Hi
I mean, it sounds odd why it would reload the files just because you adjust brightness so
i was wondering if you cant just change the code to make it not reload.I don't know which functions, it was more a generic thought. :)
If you have a python debugger handy,
then it should not be that complex to find out why brightness change will reload the shapes
and make that not happen when its just brightness being adjusted. -
Okay Okay. I will make some changes to the code and probably paste it here so we can talk about it. Before that I have just one question, how can I check using an IF condition whether the shape was moved? (Perhaps comparing the coordinates from the previous point ?)
-
Okay Okay. I will make some changes to the code and probably paste it here so we can talk about it. Before that I have just one question, how can I check using an IF condition whether the shape was moved? (Perhaps comparing the coordinates from the previous point ?)
Hi.
Ok. still not sure how you adjust brightness but maybe dont matter.Well, the normal way to track if something moved
would be to take the difference between now and the last position.
So yes, that should work fine. -
So my shape from the txt file (annotation file) is :
shapes from the file: [('Object_A', [(14, 134), (816, 134), (816, 458), (14, 458)], None, None, False)]
Then in the file canvas.py a function is written for moveMouseEvent() which includes the panning of the shape, moving of the shape and is as follows:
if Qt.LeftButton & ev.buttons(): if self.selectedVertex(): self.boundedMoveVertex(pos) self.shapeMoved.emit() self.repaint() elif self.selectedShape and self.prevPoint: self.overrideCursor(CURSOR_MOVE) self.boundedMoveShape(self.selectedShape, pos) self.shapeMoved.emit() self.repaint() print(f'selected shape prev point: {self.selectedShape.points}')
I added the print statement just to output the coordinates of the shape when moved and the output is as follows:
selected shape prev point: [PyQt5.QtCore.QPointF(14.0, 133.0), PyQt5.QtCore.QPointF(816.0, 133.0), PyQt5.QtCore.QPointF(816.0, 457.0), PyQt5.QtCore.QPointF(14.0, 457.0)] selected shape prev point: [PyQt5.QtCore.QPointF(17.0, 131.0), PyQt5.QtCore.QPointF(819.0, 131.0), PyQt5.QtCore.QPointF(819.0, 455.0), PyQt5.QtCore.QPointF(17.0, 455.0)] selected shape prev point: [PyQt5.QtCore.QPointF(23.0, 131.0), PyQt5.QtCore.QPointF(825.0, 131.0), PyQt5.QtCore.QPointF(825.0, 455.0), PyQt5.QtCore.QPointF(23.0, 455.0)] selected shape prev point: [PyQt5.QtCore.QPointF(33.0, 131.0), PyQt5.QtCore.QPointF(835.0, 131.0), PyQt5.QtCore.QPointF(835.0, 455.0), PyQt5.QtCore.QPointF(33.0, 455.0)]
I am trying to save all these points in a concatenated list and then just use the last list of QPointF to compare with the shapes from the file. To compare I want to convert QPointF points as shown above in a list like [[(1, 2), (3, 4), (5, 6), (7, 8)], [(9, 10), (11, 12), (13, 14), (15, 16)]] . I can do this part but how do I convert the QPointF to list of lists and where can I access these points in the file labelImg.py?