Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 08.09.2023, 10:58   #1
omelsn@mail.ru
Пользователь
 
Регистрация: 27.03.2023
Сообщений: 13
По умолчанию Перестал работать код при переходе с Win на Lin

На Win код распозновал лица и записывал результат в книгу excel, при переходе на Lin Ubuntu, код запускается и вылетает. поменял вот эту строку rgb_small_frame = small_frame[:, :, ::-1] на эту
rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB), код стал работать криво

import face_recognition
import cv2
import numpy as np
import openpyxl
import pandas as pd
from datetime import datetime


excel_data_df = pd.read_excel('result.xlsx', sheet_name='Sheet', header=None)

excel_data_df.iloc[:,1:] = excel_data_df.iloc[:,1:].apply(lambda x: pd.to_datetime(x).dt.date)



list = excel_data_df.values.tolist()

k = datetime.now().date()


# This is a demo of running face recognition on live video from your webcam. It's a little more complicated than the
# other example, but it includes some basic performance tweaks to make things run a lot faster:
# 1. Process each video frame at 1/4 resolution (though still display it at full resolution)
# 2. Only detect faces in every other frame of video.

# PLEASE NOTE: This example requires OpenCV (the `cv2` library) to be installed only to read from your webcam.
# OpenCV is *not* required to use the face_recognition library. It's only required if you want to run this
# specific demo. If you have trouble installing it, try any of the other demos that don't require it instead.

# Get a reference to webcam #0 (the default one)
video_capture = cv2.VideoCapture(0)

# Load a sample picture and learn how to recognize it.
sam_image = face_recognition.load_image_file("s am.jpeg")
sam_face_encoding = face_recognition.face_encodings(sam _image)[0]

# Load a second sample picture and learn how to recognize it.
sama_image = face_recognition.load_image_file("s ama.jpeg")
sama_face_encoding = face_recognition.face_encodings(sam a_image)[0]

# Create arrays of known face encodings and their names
known_face_encodings = [
sam_face_encoding,
sama_face_encoding
]
known_face_names = [
"sam",
"sama"
]

# Initialize some variables
face_locations = []
face_encodings = []
face_names = []
process_this_frame = True

while True:
# Grab a single frame of video
ret, frame = video_capture.read()

# Only process every other frame of video to save time
if process_this_frame:
# Resize frame of video to 1/4 size for faster face recognition processing
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)

# Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
rgb_small_frame = small_frame[:, :, ::-1]

# Find all the faces and face encodings in the current frame of video
face_locations = face_recognition.face_locations(rgb _small_frame)
face_encodings = face_recognition.face_encodings(rgb _small_frame, face_locations)

face_names = []
for face_encoding in face_encodings:
# See if the face is a match for the known face(s)
matches = face_recognition.compare_faces(know n_face_encodings, face_encoding)
name = "Unknown"

# # If a match was found in known_face_encodings, just use the first one.
# if True in matches:
# first_match_index = matches.index(True)
# name = known_face_names[first_match_index]

# Or instead, use the known face with the smallest distance to the new face
face_distances = face_recognition.face_distance(know n_face_encodings, face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index]

face_names.append(name)

# c = name

for i in range(len(list)):
for j in range(len(list[i])):
if name in list[i]:
if k not in list[i]:
list[i].append(k)

excel_data_df = pd.DataFrame(list)

for row in list:
print(' '.join([str(elem) for elem in row]))

excel_data_df.to_excel (r'result.xlsx', sheet_name="Sheet", index= False, header= False, )




process_this_frame = not process_this_frame


# Display the results
for (top, right, bottom, left), name in zip(face_locations, face_names):
# Scale back up face locations since the frame we detected in was scaled to 1/4 size
top *= 4
right *= 4
bottom *= 4
left *= 4

# Draw a box around the face
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

# Draw a label with a name below the face
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)

# Display the resulting image
cv2.imshow('Video', frame)

# Hit 'q' on the keyboard to quit!
if cv2.waitKey(1) & 0xFF == ord('q'):
break



# Release handle to the webcam
video_capture.release()
cv2.destroyAllWindows()
omelsn@mail.ru вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Перестал работать запрос при переходе с mySQL 5.5 на mySQL 8.0 volni SQL, базы данных 3 13.04.2021 15:26
Программа перестает работать при переходе на другое приложение A1978 Общие вопросы Delphi 2 09.12.2016 22:06
Перестал работать код Оксана33 Microsoft Office Excel 6 07.10.2015 21:10
Перестал работать css impulsgraw HTML и CSS 8 22.08.2011 21:28
перестал работать cd-rom Betty Компьютерное железо 7 22.08.2009 09:10