在菜单edit和鼠标右键 增加图片左右旋转功能
This commit is contained in:
parent
aa12eb2637
commit
4df7ada91d
|
@ -27,7 +27,12 @@ import json
|
|||
import cv2
|
||||
|
||||
|
||||
|
||||
__dir__ = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
import numpy as np
|
||||
from labelme import LabelFile
|
||||
|
||||
sys.path.append(__dir__)
|
||||
sys.path.append(os.path.abspath(os.path.join(__dir__, '../..')))
|
||||
sys.path.append("..")
|
||||
|
@ -267,6 +272,8 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||
self.colorDialog = ColorDialog(parent=self)
|
||||
self.zoomWidgetValue = self.zoomWidget.value()
|
||||
|
||||
self.msgBox = QMessageBox()
|
||||
|
||||
########## thumbnail #########
|
||||
hlayout = QHBoxLayout()
|
||||
m = (0, 0, 0, 0)
|
||||
|
@ -460,6 +467,12 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||
undoLastPoint = action(getStr("undoLastPoint"), self.canvas.undoLastPoint,
|
||||
'Ctrl+Z', "undo", getStr("undoLastPoint"), enabled=False)
|
||||
|
||||
rotateLeft = action(getStr("rotateLeft"), self.rotateLeftImg,
|
||||
'Ctrl+Alt+L', "rotateLeft", getStr("rotateLeft"), enabled=False)
|
||||
|
||||
rotateRight = action(getStr("rotateRight"), self.rotateRightImg,
|
||||
'Ctrl+Alt+R', "rotateRight", getStr("rotateRight"), enabled=False)
|
||||
|
||||
undo = action(getStr("undo"), self.undoShapeEdit,
|
||||
'Ctrl+Z', "undo", getStr("undo"), enabled=False)
|
||||
|
||||
|
@ -524,12 +537,13 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||
fitWindow=fitWindow, fitWidth=fitWidth,
|
||||
zoomActions=zoomActions, saveLabel=saveLabel,
|
||||
undo=undo, undoLastPoint=undoLastPoint,open_dataset_dir=open_dataset_dir,
|
||||
rotateLeft=rotateLeft,rotateRight=rotateRight,
|
||||
fileMenuActions=(
|
||||
opendir, open_dataset_dir, saveLabel, resetAll, quit),
|
||||
beginner=(), advanced=(),
|
||||
editMenu=(createpoly, edit, copy, delete,singleRere,None, undo, undoLastPoint,
|
||||
None, color1, self.drawSquaresOption),
|
||||
beginnerContext=(create, edit, copy, delete, singleRere),
|
||||
None, rotateLeft, rotateRight, None, color1, self.drawSquaresOption),
|
||||
beginnerContext=(create, edit, copy, delete, singleRere, rotateLeft, rotateRight,),
|
||||
advancedContext=(createMode, editMode, edit, copy,
|
||||
delete, shapeLineColor, shapeFillColor),
|
||||
onLoadActive=(
|
||||
|
@ -781,6 +795,49 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||
self.actions.create.setEnabled(False)
|
||||
self.actions.undoLastPoint.setEnabled(True)
|
||||
|
||||
def rotateLeftImg(self, _value=False):
|
||||
|
||||
filename = self.mImgList[self.currIndex]
|
||||
|
||||
if os.path.exists(filename):
|
||||
_value = True
|
||||
self.actions.rotateLeft.setEnabled(_value)
|
||||
pix = cv2.imread(filename)
|
||||
pix = np.rot90(pix, k=1)
|
||||
cv2.imwrite(filename, pix)
|
||||
self.canvas.update()
|
||||
self.loadFile(filename)
|
||||
else:
|
||||
_value = False
|
||||
if self.lang == 'ch':
|
||||
self.msgBox.warning(self, "提示", "\n 请从图片列表选择一个需要旋转的图片,且确保图片存在!")
|
||||
else:
|
||||
self.msgBox.warning(self, "Warn", "\n Please select an image from the list of images to rotate and make sure the image exists!")
|
||||
|
||||
self.actions.rotateLeft.setEnabled(_value)
|
||||
|
||||
def rotateRightImg(self, _value=False):
|
||||
|
||||
filename = self.mImgList[self.currIndex]
|
||||
|
||||
if os.path.exists(filename):
|
||||
_value = True
|
||||
self.actions.rotateRight.setEnabled(_value)
|
||||
pix = cv2.imread(filename)
|
||||
pix = np.rot90(pix, k=-1)
|
||||
cv2.imwrite(filename, pix)
|
||||
self.canvas.update()
|
||||
self.loadFile(filename)
|
||||
else:
|
||||
_value = False
|
||||
|
||||
if self.lang == 'ch':
|
||||
self.msgBox.warning(self, "提示", "\n 请从图片列表选择一个需要旋转的图片,且确保图片存在!")
|
||||
else:
|
||||
self.msgBox.warning(self, "Warn", "\n Please select an image from the list of images to rotate and make sure the image exists!")
|
||||
|
||||
self.actions.rotateRight.setEnabled(_value)
|
||||
|
||||
def toggleDrawingSensitive(self, drawing=True):
|
||||
"""In the middle of drawing, toggling between modes should be disabled."""
|
||||
self.actions.editMode.setEnabled(not drawing)
|
||||
|
@ -1421,6 +1478,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||
|
||||
def loadRecent(self, filename):
|
||||
if self.mayContinue():
|
||||
print(filename,"======")
|
||||
self.loadFile(filename)
|
||||
|
||||
def scanAllImages(self, folderPath):
|
||||
|
@ -1456,7 +1514,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||
self.lastOpenDir = targetDirPath
|
||||
self.importDirImages(targetDirPath)
|
||||
|
||||
def openDatasetDirDialog(self, _value=False): #1458
|
||||
def openDatasetDirDialog(self,):
|
||||
if not self.mayContinue():
|
||||
return
|
||||
|
||||
|
@ -1467,7 +1525,7 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||
if self.lang == 'ch':
|
||||
self.msgBox.warning(self, "提示", "\n 原文件夹已不存在,请从新选择数据集路径!")
|
||||
else:
|
||||
self.msgBox.warning (self, "Warn", "\n The original folder no longer exists, please choose the data set path again!")
|
||||
self.msgBox.warning(self, "Warn", "\n The original folder no longer exists, please choose the data set path again!")
|
||||
|
||||
self.actions.open_dataset_dir.setEnabled(False)
|
||||
defaultOpenDirPath = os.path.dirname(self.filePath) if self.filePath else '.'
|
||||
|
@ -1520,6 +1578,9 @@ class MainWindow(QMainWindow, WindowMixin):
|
|||
self.actions.AutoRec.setEnabled(True)
|
||||
self.actions.reRec.setEnabled(True)
|
||||
self.actions.open_dataset_dir.setEnabled(True)
|
||||
self.actions.rotateLeft.setEnabled(True)
|
||||
self.actions.rotateRight.setEnabled (True)
|
||||
|
||||
|
||||
|
||||
def openPrevImg(self, _value=False):
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -18,6 +18,8 @@
|
|||
<file alias="quit">resources/icons/quit.png</file>
|
||||
<file alias="copy">resources/icons/copy.png</file>
|
||||
<file alias="edit">resources/icons/edit.png</file>
|
||||
<file alias="rotateLeft">resources/icons/rotateLeft.png</file>
|
||||
<file alias="rotateRight">resources/icons/rotateRight.png</file>
|
||||
<file alias="open">resources/icons/open.png</file>
|
||||
<file alias="save">resources/icons/save.png</file>
|
||||
<file alias="format_voc">resources/icons/format_voc.png</file>
|
||||
|
|
|
@ -86,6 +86,8 @@ detectionBoxposition=检测框位置
|
|||
recognitionResult=识别结果
|
||||
creatPolygon=四点标注
|
||||
drawSquares=正方形标注
|
||||
rotateLeft=图片左旋转90度
|
||||
rotateRight=图片右旋转90度
|
||||
saveRec=保存识别结果
|
||||
tempLabel=待识别
|
||||
nullLabel=无法识别
|
||||
|
|
|
@ -85,6 +85,8 @@ iconList=Icon List
|
|||
detectionBoxposition=Detection box position
|
||||
recognitionResult=Recognition result
|
||||
creatPolygon=Create Quadrilateral
|
||||
rotateLeft=Left turn 90 degrees
|
||||
rotateRight=Right turn 90 degrees
|
||||
drawSquares=Draw Squares
|
||||
saveRec=Save Recognition Result
|
||||
tempLabel=TEMPORARY
|
||||
|
|
Loading…
Reference in New Issue