Python 使用PyQt从QGIS插件拍摄照片

Python 使用PyQt从QGIS插件拍摄照片,python,image,pyqt,qgis,Python,Image,Pyqt,Qgis,我在插件中有一个按钮,可以拍摄照片,并将其与QGIS中的一个图层功能相关联 我的目标是选择一个功能,打开相机视图(取景器),拍摄一张照片,并将其以功能id和日期时间作为文件名保存(例如20210412-112351_223.jpg) 为此,我使用下面的代码 问题是,当我在笔记本电脑中使用这个插件时,拍摄的照片是1280x720,但对于Surface Book 3,结果照片是640x320 可以在代码中设置图片的大小吗 从PyQt5.QtWidgets导入* 从PyQt5.qt导入多媒体* 从Py

我在插件中有一个按钮,可以拍摄照片,并将其与QGIS中的一个图层功能相关联

我的目标是选择一个功能,打开相机视图(取景器),拍摄一张照片,并将其以功能id和日期时间作为文件名保存(例如20210412-112351_223.jpg)

为此,我使用下面的代码

问题是,当我在笔记本电脑中使用这个插件时,拍摄的照片是1280x720,但对于Surface Book 3,结果照片是640x320

可以在代码中设置图片的大小吗

从PyQt5.QtWidgets导入*
从PyQt5.qt导入多媒体*
从PyQt5.QtMultimediaWidgets导入*
从qgis.core导入(QgsProject,
Qgis,
QgsExpressionContextUtils)
从qgis.utils导入iface
导入操作系统
导入时间
creaventana类(QMainWindow):
定义初始化(自):
super()。\uuuu init\uuuuu()
self.setGeometry(0,01280720)
self.setStyleSheet(“背景:浅灰色;”)
self.available\u cameras=QCameraInfo.availableCameras()
如果不是自备摄像头:
iface.messageBar().pushMessage('No hay cámaras','El dispositivo No tiene ninguna cámara',
级别=Qgis.Warning,
持续时间=5)
self.status=QStatusBar()
self.status.setStyleSheet(“背景:白色;”)
self.setStatusBar(self.status)
self.viewfinder=QCameraViewfinder()
self.viewfinder.show()
self.setCentralWidget(self.viewfinder)
自行选择摄像头(0)
工具栏=QToolBar(“Cámara”)
self.addToolBar(工具栏)
点击动作=QAction(“Hacer foto”,self)
单击动作。设置状态(“Esto hace la foto”)
单击操作。设置工具提示(“Hacer foto”)
点击动作。触发。连接(自我。点击照片)
工具栏.添加操作(单击操作)
摄像机\选择器=QComboBox()
摄像头选择器。设置状态(“Cámara frontal/trasera”)
摄像头选择器。设置工具提示(“Elegir cámara”)
摄像头选择器。设置工具提示持续时间(2500)
摄像机\选择器.附加项([camera.description())
适用于自备相机。可用的\u相机])
摄像头选择器.currentIndexChanged.connect(自选择摄像头)
工具栏.addWidget(摄像头选择器)
toolbar.setStyleSheet(“背景:白色;”)
self.setWindowTitle(“PyQt5 Cam”)
def select_摄像头(自身,i):
self.camera=QCamera(自备摄像头[i])
self.camera.setViewfinder(self.viewfinder)
self.camera.setCaptureMode(QCamera.CaptureStillImage)
self.camera.error.connect(lambda:self.alert(self.camera.errorString()))
self.camera.start()
self.capture=QCameraImageCapture(self.camera)
self.capture.error.connect(lambda error\u msg,error,
msg:self.alert(msg))
self.capture.imagecapture.connect(lambda d,i:self.status.showMessage(“Imagen tomada:+str(self.save_seq)))
self.current\u camera\u name=self.available\u camera[i].description()
self.save_seq=0
def点击照片(自身):
individuos=QgsProject.instance().mapLayersByName('individuos')[0]
IndividualSeleccionado=IndividualDuos.selectedFeatures()
对于individuoSeleccionado中的individuo:
IDID=individudo['id\u ind']
timestamp=time.strftime(“%Y%m%d-%H%m%S”)
ruta='D:/fotos/'
self.capture.capture(os.path.join(ruta,“%s\u%s.jpg”%(idid,timestamp)))
self.save_seq+=1
def警报(自我,消息):
错误=QErrorMessage(自我)
错误。showMessage(msg)
def abrecamara(自我):
individuos=QgsProject.instance().mapLayersByName('individuos')[0]
IndividualSeleccionado=IndividualDuos.selectedFeatures()
CuentIndividualSeleccionado=len(列表(IndividualSeleccionado))
如果CuentaIndividualOseleccionado==1:
ventana=creaventana()
文塔纳秀
elif Cuentaloseleccionado>1:
iface.messageBar().pushMessage('Selección','Solo puede haber un individual seleccionado',
级别=Qgis.Warning,
持续时间=5)
elif CuentaIndividualOseleccionado==0:
iface.messageBar().pushMessage('Selección','Tiene que haber al-menos un individual seleccionado',
级别=Qgis.Warning,
持续时间=5)

虽然您提到了这个问题,但不清楚预期结果。这里的要求是什么?请用更多细节充实问题。我编辑问题是为了添加有关需求的详细信息。您是否尝试将
setResolution
设置为预期的分辨率
imagesettings=self.capture.encodingSettings()
imagesettings.setResolution(1280720)
然后
self.capture.setEncodingSettings(imagesettings)
。我无法使用Surface Laptop测试此功能是的,我尝试过,在click_photo功能中,但它不起作用,生成的图片仍然是640x320。如果Surface Book默认分辨率不允许1280x720怎么办?根据他们的展示,这就是我所看到的,对于
15.0“分辨率为3240x2160
13.5”:3000x2000
。也许,您可以尝试设置曲面书本的最大分辨率吗?