Ask Your Question

irum's profile - activity

2020-03-14 12:06:34 -0600 received badge  Popular Question (source)
2020-02-02 21:34:23 -0600 received badge  Famous Question (source)
2019-04-26 18:16:42 -0600 received badge  Notable Question (source)
2018-11-16 08:32:24 -0600 received badge  Popular Question (source)
2016-12-25 13:28:59 -0600 asked a question remove camera lag open CV python

i am working on Odroid and running a face detection using open cv python on it. but there is too much lag in the camera. i have tried a lot of things but couldn't remove the lag. please suggest how can i remove the lag. i want to detect faces from at least 15 feet for that i need a high resolution, but high resolution causes more lag. currently i am having 2 second lag between frames. if there are any suggestions please share.

2016-12-25 13:23:34 -0600 asked a question Remove camera lag in opencv python

i am working on Odroid and running a face detection using open cv python on it. but there is too much lag in the camera. i have tried a lot of things but couldn't remove the lag. please suggest how can i remove the lag. i want to detect faces from at least 15 feet for that i need a high resolution, but high resolution causes more lag. currently i am having 2 second lag between frames..... if there are any suggestions please share.

2016-11-16 01:21:54 -0600 commented answer openCV imshow does not show image

i have solved it ... and Thanks a lot for the help :)

2016-11-11 04:25:16 -0600 commented answer openCV imshow does not show image

Thank you Berak my problem is solved but now i am having another problem i was trying to track the face but the tracking window doesn't do that its just span to half of the display window, is there anything that you can help with ?

2016-11-11 04:22:12 -0600 received badge  Scholar (source)
2016-11-11 01:55:49 -0600 asked a question openCV imshow does not show image

Below is my code and i am having this error : File "imgTrack.py", line 37, in <module> cv2.imshow('img2',img2) cv2.error: /home/irum/OpenCv/modules/highgui/src/window.cpp:269: error: (-215) size.width>0 && size.height>0 in function imshow

Whats there that i am missing?

import numpy as np
import cv2
from matplotlib import pyplot as plt
cap = cv2.VideoCapture(0)

# take first frame of the video
ret,frame = cap.read()

# setup initial location of window
r,h,c,w = 250,90,400,125  # simply hardcoded the values
track_window = (c,r,w,h)

# set up the ROI for tracking
roi = frame[r:r+h, c:c+w]
hsv_roi =  cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv_roi, np.array((0., 60.,32.)), np.array((180.,255.,255.)))
roi_hist = cv2.calcHist([hsv_roi],[0],mask,[180],[0,180])
cv2.normalize(roi_hist,roi_hist,0,255,cv2.NORM_MINMAX)

# Setup the termination criteria, either 10 iteration or move by atleast 1 pt
term_crit = ( cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1 )

while(1):
    ret ,frame = cap.read()

    if ret == True:
        hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
        dst = cv2.calcBackProject([hsv],[0],roi_hist,[0,180],1)

        # apply meanshift to get the new location
        ret, track_window = cv2.CamShift(dst, track_window, term_crit)

        # Draw it on image
        pts = cv2.cv.BoxPoints(ret)
        pts = np.int0(pts)
        img2 = cv2.polylines(frame,[pts],True, 255,2)
        cv2.imshow('img2',img2)


        k = cv2.waitKey(60) & 0xff
        if k == 27:
            break
        else:
            cv2.imwrite(chr(k)+".jpg",img2)

    else:
        break

cv2.destroyAllWindows()
cap.release()
2016-11-04 05:33:46 -0600 commented answer passing parameters to cv2.kmeans in python

i solved the problem by using sklearn.cluster.KMeans it is making clusters now. I used the piece of code in you answer and then just passed the images to KMeans. `#Convert Images to Float32 images = np.asarray(images, np.float32) N = len(images) images = images.reshape(N,-1)

using kmeans clustring having 5 clusters

kmeans = KMeans(n_clusters=5)

passing images to kmeans

kmeans.fit(images)

centroids = kmeans.cluster_centers_ labels = kmeans.labels_ ` its working... Thank you for the help.

2016-11-04 05:29:15 -0600 received badge  Supporter (source)
2016-11-03 05:49:22 -0600 commented question passing parameters to cv2.kmeans in python

yes determining k is also another problem so i thought for now i can use k=10 because i have not that much different people in dataset. secondly if there is any other technique that can be more useful i will be very happy to try.

2016-11-03 05:46:35 -0600 commented answer passing parameters to cv2.kmeans in python

i am having this error now. you can see the code above i have edited the code. Traceback (most recent call last): File "Kmeans2.py", line 39, in <module> ret,label,center=cv2.kmeans(images,2,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS) TypeError: an integer is required

2016-11-03 05:22:13 -0600 commented question passing parameters to cv2.kmeans in python

(images, lables) = [numpy.array(lis) for lis in [images, lables]] these are two numpy arrays, one has faces and other has lables. i need to cluster image data, i want to differentiate one face from another so i can get same faces in one cluster.

2016-11-03 05:15:31 -0600 commented question passing parameters to cv2.kmeans in python

i am doing detection and recognition , any face which is detected and not recognized is saved in a dataset. after a day my algorithm start doing clustering on that dataset in order to put them in a database of known people and each cluster will have a specific name after that. So when i tried doing clustering using open cv KMeans i am having different errors. Because i think i am passing wrong samples MAY BE. Problem is that i am asking how can i pass the images numpy array to this cv2.KMeans function ?

2016-11-03 04:54:33 -0600 commented question passing parameters to cv2.kmeans in python

i will use this clustered data for face recognition .... basically i am doing clustering for face-recognition

2016-11-03 04:39:42 -0600 asked a question passing parameters to cv2.kmeans in python

i have a dataset of images and i want to do clustering on it. I have read the openCV documentations of kmeans but i just do not get it properly. Below is my code and i have no idea how can i pass images to the kmeans() and how to send all the clusters into different folders.

import cv2, sys, numpy, os
import matplotlib.pyplot as plt
from matplotlib import style
style.use("ggplot")
from sklearn.cluster import KMeans


fn_dir2 = 'unknown'
path2='/home/irum/Desktop/Face-Recognition/thakarrecog/unknown/UNKNOWNS'

# Create a list of images and a list of corresponding names
(images, lables, names, id) = ([], [], {}, 0)

#reading images from dataset
for (subdirs, dirs, files) in os.walk(fn_dir2):
    for subdir in dirs:
        names[id] = subdir 
        subjectpath = os.path.join(fn_dir2, subdir) 
        for filename in os.listdir(subjectpath):
            path = subjectpath + '/' + filename
            lable = id
            images.append(cv2.imread(path, 0))
            lables.append(int(lable))

        id += 1
#converting images and lables to numpy arrays 
(images, lables) = [numpy.array(lis) for lis in [images, lables]]
print "length images", len(images)
print type(images)
print "length lables", len(lables)

criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 1.0)

images = np.asarray(images, np.float32)
N = len(images)
images = images.reshape(N,-1)
ret,label,center=cv2.kmeans(images,k,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)

now i am having this error Traceback (most recent call last): File "Kmeans2.py", line 39, in <module> ret,label,center=cv2.kmeans(images,2,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS) TypeError: an integer is required

2016-10-25 03:48:20 -0600 commented question recognition giving error of training and test data (size not same)

i have a working copy of the code and that is working properly just slow.... i need to make that fast

2016-10-25 03:10:33 -0600 commented question recognition giving error of training and test data (size not same)

i am having a very slow fps on raspberry pi when i run this code without this part and do the recognition straight away if counter<20: frame_list.append(eq) counter +=1 print "frame_list", len(frame_list) # Try to recognize the face for i in range(len(eq)): eq_i = eq[i] i thought if i do recognition for limited faces every time it would be better. but i am having an error. point is i just want to make fps better.

2016-10-25 02:50:25 -0600 asked a question recognition giving error of training and test data (size not same)

i want to run recognition for only 20 eq which are the list of faces on that i want to run recognition. but it is giving me error that training and test images are not of same size but they are same size. this is the error:

OpenCV Error: Bad argument (Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with 10304 elements, but got 112.) in predict, file /home/irum/OpenCv/modules/contrib/src/facerec.cpp, line 623
Traceback (most recent call last):
  File "facerec-opencv.py", line 84, in <module>
    prediction  = model.predict(eq_i)
cv2.error: /home/irum/OpenCv/modules/contrib/src/facerec.cpp:623: error: (-5) Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with 10304 elements, but got 112. in function predict

and here is my code:

# facerec.py
import cv2, sys, numpy, os
import json
size = 3
fn_dir2 = 'unknown'
fn_haar = 'haarcascade_frontalface_default.xml'
fn_dir = 'att_faces'
path2='/home/irum/Desktop/Face-Recognition/thakarrecog/unknown/UNKNOWNS'
path='/home/irum/Desktop/Face-Recognition/thakarrecog/att_faces'
# Part 1: Create fisherRecognizer
print('Training...')

# Create a list of images and a list of corresponding names
(images, lables, names, id) = ([], [], {}, 0)


for (subdirs, dirs, files) in os.walk(fn_dir):
    for subdir in dirs:
        names[id] = subdir 
        subjectpath = os.path.join(fn_dir, subdir) 
        for filename in os.listdir(subjectpath):
            path = subjectpath + '/' + filename
            lable = id
            images.append(cv2.imread(path, 0))
            lables.append(int(lable))
        id += 1



(im_width, im_height) = (112, 92)

# Create a Numpy array from the two lists above
(images, lables) = [numpy.array(lis) for lis in [images, lables]]

# OpenCV trains a model from the images

model = cv2.createFisherFaceRecognizer()
model.train(images, lables)

# Part 2: Use fisherRecognizer on camera stream
haar_cascade = cv2.CascadeClassifier(fn_haar)
# Capturing camera feed
webcam = cv2.VideoCapture(0)
webcam.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 1920)
webcam.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 1080)
frame_list=[]
counter = 0
while True:

    # Reading Frames from live stream
    (rval, frame) = webcam.read()
    frame=cv2.flip(frame,1,0)

    #Convert frame into gray
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    #gray = cv2.GaussianBlur(gray, (21, 21), 0)
    # Resize the gary 
    mini = cv2.resize(gray, (gray.shape[1] / size, gray.shape[0] / size))
    # Detecting the face 
    faces = haar_cascade.detectMultiScale(mini,1.1, 5)


    for i in range(len(faces)):
        face_i = faces[i]
        (x, y, w, h) = [v * size for v in face_i]
        # Croping face
        face = gray[y:y + h, x:x + w]
        face_resize = cv2.resize(face, (im_width, im_height))
        # Eualize Histogram
        eq = cv2.equalizeHist(face_resize)
        if counter<20:
            frame_list.append(eq)
                    counter +=1
                    print "frame_list", len(frame_list)
        # Try to recognize the face
        for i in range(len(eq)):
           eq_i = eq[i]
           prediction  = model.predict(eq_i)
           print "Recognition Prediction" ,prediction
           # Draw rectangle around the face
           cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 3)

           if prediction[1]<=800:

             cv2.putText(frame,
                     '%s - %.0f' % (names[prediction[0]],prediction[1]),
                     (x-10, y-10), cv2.FONT_HERSHEY_DUPLEX,1,(255, 255, 0))
             break

           else:

             print "for prediction more than 600"
             print "prediction ...
(more)
2016-10-25 02:39:40 -0600 commented question What type of result predict function of fisherface recognizer returns

thankyou :)... let me try this now

2016-10-25 00:52:48 -0600 received badge  Enthusiast
2016-10-25 00:52:42 -0600 received badge  Enthusiast
2016-10-24 04:49:57 -0600 commented question What type of result predict function of fisherface recognizer returns

normally true positive is less than 500 and true negative is more than 700. between 500 and 700 sometimes it recognizes accurately but some times it confuses some faces with other faces. that is why i am not sure about the threshold value.

2016-10-24 04:34:27 -0600 commented question What type of result predict function of fisherface recognizer returns

ok now i get it.... secondly can you tell me how much confidence level should i take to tell confidently that the person is recognized correctly.

2016-10-24 04:30:32 -0600 commented question What type of result predict function of fisherface recognizer returns

i have attached the code so you can take a look.

2016-10-24 04:18:56 -0600 commented question What type of result predict function of fisherface recognizer returns

ok can you tell me what actually is this id ? its value changes from 1 to 4 for some faces.

2016-10-24 03:34:10 -0600 commented question What type of result predict function of fisherface recognizer returns

i am using openCV to detect faces and then i start recognizing them using fisherface recognizer. and i didn't post my code above i posted the result of the FaceRecognizer.predict function.

2016-10-24 03:20:52 -0600 asked a question What type of result predict function of fisherface recognizer returns

i am doing face recognition in python using openCV and fisherface algorithm. the predict function prediction = model.predict(image) gives results like this distance : (2, 483.88206400085585) i do not know what actually is this distance': (2, 483.88206400085585). In this result483.8806400085585 is the distance but i do not have any idea about the 2this value changes between 1 to 4. that is my code:

# facerec.py
import cv2, sys, numpy, os
import json
size = 3
fn_dir2 = 'unknown'
fn_haar = 'haarcascade_frontalface_default.xml'
fn_dir = 'att_faces'
path2='/home/irum/Desktop/Face-Recognition/thakarrecog/unknown/UNKNOWNS'
path='/home/irum/Desktop/Face-Recognition/thakarrecog/att_faces'
# Part 1: Create fisherRecognizer
print('Training...')

# Create a list of images and a list of corresponding names
(images, lables, names, id) = ([], [], {}, 0)


for (subdirs, dirs, files) in os.walk(fn_dir):
    for subdir in dirs:
        names[id] = subdir 
        subjectpath = os.path.join(fn_dir, subdir) 
        for filename in os.listdir(subjectpath):

            path = subjectpath + '/' + filename
            lable = id
            images.append(cv2.imread(path, 0))
            lables.append(int(lable))
        id += 1



(im_width, im_height) = (112, 92)

# Create a Numpy array from the two lists above
(images, lables) = [numpy.array(lis) for lis in [images, lables]]

# OpenCV trains a model from the images

model = cv2.createFisherFaceRecognizer()
model.train(images, lables)

# Part 2: Use fisherRecognizer on camera stream
haar_cascade = cv2.CascadeClassifier(fn_haar)
# Capturing camera feed
webcam = cv2.VideoCapture(0)
webcam.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 1920)
webcam.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 1080)

while True:
    # Reading Frames from live stream
    (rval, frame) = webcam.read()
    frame=cv2.flip(frame,1,0)
    #Convert frame into gray
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    #gray = cv2.GaussianBlur(gray, (21, 21), 0)
    # Resize the gary 
    mini = cv2.resize(gray, (gray.shape[1] / size, gray.shape[0] / size))
    # Detecting the face 
    faces = haar_cascade.detectMultiScale(mini,1.1, 5)
    for i in range(len(faces)):
        face_i = faces[i]
        (x, y, w, h) = [v * size for v in face_i]
        # Croping face
        face = gray[y:y + h, x:x + w]
        face_resize = cv2.resize(face, (im_width, im_height))
        # Eualize Histogram
        eq = cv2.equalizeHist(face_resize)

        # Try to recognize the face

        prediction  = model.predict(eq)
        print "Recognition Prediction" ,prediction
        # Draw rectangle around the face
        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 3)

        # Write the name of recognized face

          result = {
                'face': {

                 'distance': prediction,
                 'coords': {
                   'x': str(faces[0][0]),
                   'y': str(faces[0][1]),
                   'width': str(faces[0][2]),
                   'height': str(faces[0][3])
                    }
                }
              }
        print "1 Result of Over all Prediction" ,result


        if prediction[0]>0 and prediction[0]<4 and prediction[1]<=500:

         result = {
            'face': {

             'distance': prediction[1],
             'coords': {
               'x': str(faces[0][0]),
               'y': str(faces[0][1]),
               'width': str(faces[0][2]),
               'height': str(faces[0][3])
                }
            }
          }

         dist = result['face']['distance']
         print "Known Face DISTANCE" , dist

         cv2.putText(frame,
                 '%s - %.0f' % (names[prediction[0]],prediction[1]),
                 (x-10, y-10), cv2.FONT_HERSHEY_DUPLEX,1,(255, 255, 0))
         break

        else:
        #if prediction[0]<=0 and prediction[0]>=4 and prediction[1]>600:
         print "for prediction more than 600"
         print "prediction", prediction 
         result = {
            'face': {

             'distance': prediction[1],
             'coords': {
               'x': str ...
(more)
2016-10-05 01:58:49 -0600 received badge  Editor (source)
2016-10-04 04:59:22 -0600 asked a question problem in making decision in fisherface if the face is known or not

i want to put a condition that if there is a known face then it executes the part where i display name of recognized person on the rectangle. but if there is an unknown face or a face with bad confidence level it should display "unknown" . my algorithm is working but sometimes it displays wrong name on a persons face. is there any way we i can solve this issue ?

facerec.py

import cv2, sys, numpy, os import json size = 4 fn_haar = 'haarcascade_frontalface_default.xml' fn_dir = 'att_faces'

Part 1: Create fisherRecognizer

print('Training...')

Create a list of images and a list of corresponding names

(images, lables, names, id) = ([], [], {}, 0) for (subdirs, dirs, files) in os.walk(fn_dir): for subdir in dirs: names[id] = subdir subjectpath = os.path.join(fn_dir, subdir) for filename in os.listdir(subjectpath): path = subjectpath + '/' + filename lable = id images.append(cv2.imread(path, 0)) lables.append(int(lable)) id += 1 (im_width, im_height) = (112, 92)

Create a Numpy array from the two lists above

(images, lables) = [numpy.array(lis) for lis in [images, lables]]

OpenCV trains a model from the images

NOTE FOR OpenCV2: remove '.face'

model = cv2.createFisherFaceRecognizer() model.train(images, lables)

Part 2: Use fisherRecognizer on camera stream

haar_cascade = cv2.CascadeClassifier(fn_haar) webcam = cv2.VideoCapture(0) while True: (rval, frame) = webcam.read() frame=cv2.flip(frame,1,0) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) mini = cv2.resize(gray, (gray.shape[1] / size, gray.shape[0] / size)) faces = haar_cascade.detectMultiScale(mini) for i in range(len(faces)): face_i = faces[i] (x, y, w, h) = [v * size for v in face_i] face = gray[y:y + h, x:x + w] face_resize = cv2.resize(face, (im_width, im_height))

    # Try to recognize the face
    prediction  = model.predict(face_resize)


    cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 3)

    # Write the name of recognized face
    # [1]
result = {
            'face': {

             'distance': prediction,
             'coords': {
               'x': str(faces[0][0]),
               'y': str(faces[0][1]),
               'width': str(faces[0][2]),
               'height': str(faces[0][3])
                }
            }
          }
print result
if prediction > 0:
    if prediction[1]>0 and prediction[1]<500:

         result = {
            'face': {

             'distance': prediction[1],
             'coords': {
               'x': str(faces[0][0]),
               'y': str(faces[0][1]),
               'width': str(faces[0][2]),
               'height': str(faces[0][3])
                }
            }
          }

         dist = result['face']['distance']
         print "DIST" , dist
         print "prediction",prediction 
         cv2.putText(frame,
                 '%s - %.0f' % (names[prediction[0]],prediction[1]),
                 (x-10, y-10), cv2.FONT_HERSHEY_PLAIN,1,(0, 255, 0))
else:
     print "prediction",prediction 
     result = {
        'face': {

         'distance': prediction[0],
         'coords': {
           'x': str(faces[0][0]),
           'y': str(faces[0][1]),
           'width': str(faces[0][2]),
           'height': str(faces[0][3])
            }
        }
      }
     dist = result['face']['distance']
     print "DIST Unknown" , dist
     cv2.putText(frame,
          'Unknown',
          (x-10, y-10), cv2.FONT_HERSHEY_PLAIN,1,(0, 255, 0))
cv2.imshow('OpenCV', frame)
key = cv2.waitKey(10)
if key == 27:
    break
2016-10-04 03:05:01 -0600 commented answer python multiprocessing performance in opencv image processing

whats the difference between distance value and the value in prediction ? how can i make it optimize using distance. what one value should i set to determine recognized face.