def start(self):
print('Stream Strat')
self.widget_stream.clear()
response = requests.post('http://192.168.122.1:8080/sony/camera', json={"method": "startLiveview","params": [],"id": 1,"version": "1.0" })
print(response.content)
response = requests.get('http://192.168.122.1:8080/liveview/liveviewstream', stream=True)
for line in response.iter_content(chunk_size=1024*1024):
if line.find(b'\xff\xd8') != -1 and line.find(b'\xff\xd9') != -1:
b_jpeg_s = line.find(b'\xff\xd8')
b_jpeg_e = line.find(b'\xff\xd9')
image_bmp = Image.open(io.BytesIO(line[b_jpeg_s:b_jpeg_e + 2]))
image_bmp.save('image.bmp')
pixmap = QPixmap('image.bmp')
self.label_image.setPixmap(pixmap)
import io
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import requests
def log_uncaught_exceptions(ex_cls, ex, tb):
text = '{}: {}:\n\n'.format(ex_cls.__name__, ex)
import traceback
text += ''.join(traceback.format_tb(tb))
QMessageBox.critical(None, 'Ошибка!', text)
quit()
sys.excepthook = log_uncaught_exceptions
class SenderMessage(QObject):
image_bytes = pyqtSignal(bytes)
def __init__(self):
super().__init__()
@pyqtSlot()
def run(self):
image_bytes = requests.get('https://dadaviz.ru/wp-content/uploads/2018/02/1-12.jpg', stream=True).content
self.image_bytes.emit(image_bytes)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("Показать изображение")
self.setGeometry(400, 200, 626, 626)
self.label_image = QLabel(self)
self.label_image.setGeometry(0, 0, 626, 626)
self.pixmap = QPixmap()
self.thread = QThread()
self.sender_message = SenderMessage()
self.sender_message.moveToThread(self.thread)
self.sender_message.image_bytes.connect(self.signalHandlerImageBytes)
self.thread.started.connect(self.sender_message.run)
self.thread.start()
def signalHandlerImageBytes(self, image_bytes):
self.pixmap.loadFromData(image_bytes)
self.label_image.setPixmap(self.pixmap)
def main():
app = QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()