Traceback (most recent call last):
File "main.py", line 55, in <module>
res=names[recognizer.predict(gray[y:y+h, x:x+w])-1]
TypeError: unsupported operand type(s) for -: 'tuple' and 'int'
This is my error . and the code is
import cv2
import numpy as np
import os
import serial
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath)
recognizer=cv2.face.createLBPHFaceRecognizer()
#Loading each image and cropping the face preparing the dataset
# for filename in os.listdir('Dataset'):
# im=cv2.imread('Dataset/'+filename,0)
# print filename
# faces = faceCascade.detectMultiScale(im, 1.3, 5)
# for (x,y,w,h) in faces:
# cv2.imwrite('Dataset/'+filename,im[y:y+h, x:x+w])
images=[]
labels=[]
for filename in os.listdir('Dataset'):
im=cv2.imread('Dataset/'+filename,0)
images.append(im)
labels.append(int(filename.split('.')[0][0]))
#print filename
names_file=open('labels.txt')
names=names_file.read().split('\n')
recognizer.train(images,np.array(labels))
print 'Training Done . . . '
font = cv2.FONT_HERSHEY_SIMPLEX
cap=cv2.VideoCapture(1)
lastRes=''
count=0
while(1):
_,frame=cap.read()
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray, 1.3, 5)
count+=1
for (x,y,w,h) in faces:
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
if count>20:
res=names[recognizer.predict(gray[y:y+h, x:x+w])-1]
if res!=lastRes :
lastRes=res
print lastRes
ser.write(lastRes)
count=0
break
cv2.imshow('frame',frame)
k = 0xFF & cv2.waitKey(10)
if k == 27:
break
cap.release()
ser.close()
cv2.destroyAllWindows()
1 11410 dwblas 626
Recognized Expert Contributor
The error message should be self explanatory. You are trying to do arithmetic on a tuple and an integer (you can only do arithmetic on types that are the same as a string + is different from an integer +). You will have to go through these calcs one at a time to see where the error is Sign in to post your reply or Sign up for a free account.
Similar topics
by: DJ Craig |
last post by:
I keep getting this error:
Fatal error: Unsupported operand types in
/usr/local/etc/httpd/htdocs/djtricities/kat/bpmchart/chart.php on line
58
I've looked for hours for some type of error, and...
|
by: Martin Koekenberg |
last post by:
Hello,
Ik get the following error when I install a new Python software
package such as Zope or PIL.
This is what I get whem I 'make' Zope :
running build_ext
Traceback (most recent call...
|
by: Rakesh |
last post by:
In my Python code fragment, I want to write a code fragment such that
the minimum element of a tuple is subtracted from all the elements of a
given
tuple.
When I execute the following python...
|
by: tanusreesen |
last post by:
Hi All,
I am completely new to python programming language.I was trying to write a program on class.But I am getting this error.Can someone please help me to solve the error I am facing.I...
|
by: Gilbert Fine |
last post by:
This is a very strange exception raised from somewhere in our program.
I have no idea how this happen. And don't know how to reproduce. It
just occurs from time to time.
Can anyone give me some...
|
by: Jordan Harry |
last post by:
I'm trying to write a simple program to calculate permutations. I created a file called "mod.py" and put the following in it:
def factorial(n):
a = n
b = n
while a>0 and b>1:
n = (n)*(b-1)...
|
by: flapjacks |
last post by:
line1 = ((0.0, -1.0), (1.0, 1.0), (2.0, 3.0), (3.0, 5.0), (4.0, 7.0), (5.0, 9.0), (6.0, 11.0), (7.0, 13.0), (8.0, 15.0), (9.0, 17.0))
line2 = ((0.0, 2.0), (1.0, 1.0), (2.0, 0.0), (3.0, -1.0), (4.0,...
|
by: pinz |
last post by:
I am making a simple vote system with yes/no radio buttons and a submit button. On submit it sends users choice to a php file - to be increased by one, related to users input. First it fetches the...
|
by: zero 0 |
last post by:
I'm a beginner at php and studying at a university.
I need to write a script which outputs the $afdeling and the corresponding "summed up" $omzet.
Then I need to output the $afdeling that has...
|
by: amakosz |
last post by:
in functions_taxes.php on line 172
here's lines 169-172 from functions_taxes.php
// Calculates Tax rounding the result
function zen_calculate_tax($price, $tax) {
global $currencies;
return...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |