def edit_name():
a3 = ln4.get()
a4 = ln5.get()
with open('imena.txt', "r+") as b:
all_words = []
line = b.readline().split()
while line:
all_words.extend(line)
line = b.readline().split()
all_words.pop(int(a3))#добавил команду, чтобы удаляла i-ый элемент перед его изменением(вставкой нового)
all_words.insert(int(a3),str(a4))
with open('imena.txt', 'w') as o:
for element in all_words:
o.write(element + '\n')
def edit_name():
a3 = ln4.get()
a4 = ln5.get()
#беру информацию из файла и изменяю её в списке
with open('imena.txt', "r+") as b:
all_words = []
line = b.readline().split()
while line:
all_words.extend(line)
line = b.readline().split()
all_words.insert(int(a3),str(a4))
#как передать список в файл, чтобы на выходе получилось как на картинках?
#пока только так, но мне нужно, чтобы было с запятой и переносом на новую строку
#а оно изменяется и добавляет запятые + изменяет положение элементов списка
with open('imena.txt', 'w') as o:
for element in all_words:
o.write(element + ',\n')
out = cv2.VideoWriter(video1, fourcc, fps, (int(w1),int(h1)))
ZeroDivisionError: float division by zero
...
h = cam.get(cv2.CAP_PROP_FRAME_HEIGHT)
prev_frame_time = time.time()
now = time.time()
duration = now - prev_frame_time
fps = 1/duration
prev_frame_time = now
...
out = cv2.VideoWriter(video1, fourcc, fps, (int(w1),int(h1)))
while(cap.isOpened()):
...
import numpy as np
import cv2
import os, os.path
import sys
import time
import pathlib
from PIL import Image
cap = cv2.VideoCapture('http://IP:Порт/video')
fourcc = cv2.VideoWriter_fourcc(*'x264')
folder = pathlib.Path().absolute()
video1 = fr'{folder}/VMF/VIDEO_{time.strftime("%m.%d.%Y_%H.%M.%S")}.avi'
out = cv2.VideoWriter(video1, fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,1)
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
Failed to load OpenH264 library: openh264-1.8.0-win64.dll
Please check environment and/or download library: https://github.com/cisco/openh264/releases
[libopenh264 @ 000001f8766e7100] Incorrect library version loaded
Could not open codec 'libopenh264': Unspecified error
[mjpeg @ 000001f8766fcf40] overread 8
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import cv2
from PyQt5.QtCore import Qt
import os
import numpy as np
from PIL import Image
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.setWindowModality(QtCore.Qt.NonModal)
Form.resize(433, 194)
Form.setWindowOpacity(1.0)
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(10, 10, 211, 31))
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(230, 100, 151, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(110, 160, 211, 31))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_4 = QtWidgets.QPushButton(Form)
self.pushButton_4.setGeometry(QtCore.QRect(240, 10, 75, 23))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_5 = QtWidgets.QPushButton(Form)
self.pushButton_5.setGeometry(QtCore.QRect(320, 10, 81, 23))
self.pushButton_5.setObjectName("pushButton_5")
self.pushButton_6 = QtWidgets.QPushButton(Form)
self.pushButton_6.setGeometry(QtCore.QRect(240, 40, 161, 23))
self.pushButton_6.setObjectName("pushButton_6")
self.lineEdit = QtWidgets.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(10, 50, 211, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(Form)
self.lineEdit_2.setGeometry(QtCore.QRect(110, 100, 111, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.label_2 = QtWidgets.QLabel(Form)
self.label_2.setGeometry(QtCore.QRect(10, 100, 91, 16))
self.label_2.setObjectName("label_2")
self.checkBox = QtWidgets.QCheckBox(Form)
self.checkBox.setGeometry(QtCore.QRect(10, 70, 162, 17))
self.checkBox.setLayoutDirection(QtCore.Qt.LeftToRight)
self.checkBox.setObjectName("checkBox")
self.label_3 = QtWidgets.QLabel(Form)
self.label_3.setGeometry(QtCore.QRect(10, 130, 71, 16))
self.label_3.setObjectName("label_3")
self.lineEdit_3 = QtWidgets.QLineEdit(Form)
self.lineEdit_3.setGeometry(QtCore.QRect(110, 130, 111, 20))
self.lineEdit_3.setObjectName("lineEdit_3")
self.pushButton_3 = QtWidgets.QPushButton(Form)
self.pushButton_3.setGeometry(QtCore.QRect(230, 130, 151, 23))
self.pushButton_3.setObjectName("pushButton_3")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Распознавнаие и идентификация лиц"))
self.label.setText(_translate("Form", "<html><head/><body><p>Введите IP-адрес видеокамеры и порт<br/>В формате - IP-адрес:Порт</p></body></html>"))
self.pushButton.setText(_translate("Form", "Отсканировать лицо"))
self.pushButton_2.setText(_translate("Form", "Внести лицо(а) в базу данных\n"
"и запустить программу\n"
""))
self.pushButton_4.setText(_translate("Form", "Справка"))
self.pushButton_5.setText(_translate("Form", "О программе"))
self.pushButton_6.setText(_translate("Form", "Выход"))
self.label_2.setText(_translate("Form", "Введите ID лица:"))
self.checkBox.setText(_translate("Form", "Использовать веб-камеру"))
self.label_3.setText(_translate("Form", "Введите имя"))
self.pushButton_3.setText(_translate("Form", "Добавить имя"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
def b1(self):
if self.checkBox.isChecked():
ui.lineEdit.setReadOnly(True)
cam = cv2.VideoCapture(0)
else:
a = ui.lineEdit.text()
cam = cv2.VideoCapture('http://' + a + '/video')
cam.set(3, 640)
cam.set(4, 480)
face_detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
face_id = ui.lineEdit_2.text()
print("\n Подключение к камере. Пожалуйста, ожидайте и смотрите в камеру...")
count = 0
while (True):
ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_detector.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
count += 1
cv2.imwrite("dataset/User." + str(face_id) + '.' + str(count) + ".jpg", gray[y:y + h, x:x + w])
cv2.imshow('image', img)
k = cv2.waitKey(100) & 0xff
if k == 27:
break
elif count >= 5:
break
print("\n Процесс завершён, можете добавить ещё лица или внести их в базу данных. ")
cam.release()
cv2.destroyAllWindows()
ui.pushButton.clicked.connect(b1)
sys.exit(app.exec_())