Ask Your Question

beta's profile - activity

2020-07-14 01:54:14 -0600 received badge  Famous Question (source)
2019-09-30 15:50:05 -0600 received badge  Notable Question (source)
2019-04-04 02:34:41 -0600 received badge  Popular Question (source)
2018-02-01 13:42:48 -0600 received badge  Popular Question (source)
2017-07-07 03:49:57 -0600 asked a question Installing opencv in docker container

Hi,

I'm trying to install opencv for this project. In the original dockerfile, they didn't give instructions for installing opencv. The dockerfile portion is follows:

FROM python:3.4-slim

#RUN apt-get -y update
RUN apt-get update && apt-get install -y \ 
    build-essential \
    cmake \
    gfortran \
    git \
    libatlas-base-dev \
    libav-tools  \
    libgtk2.0-dev \
    libjasper-dev \
    libjpeg-dev \
    libopencv-dev \
    libpng-dev \
    libtiff-dev \
    libvtk6-dev \
    pkg-config \
    python-dev \
    python-numpy \
    python-opencv \
    python-pycurl \
    qt5-default \
    unzip \
    webp \
    wget \
    zlib1g-dev 
    #&& apt-get clean && rm -rf /tmp/* /var/tmp/*

RUN mkdir -p ~/opencv cd ~/opencv && \
    wget https://github.com/Itseez/opencv/archive/3.2.0.zip && \
    unzip 3.2.0.zip && \
    rm 3.2.0.zip && \
    cd opencv-3.2.0 && \
    mkdir build && \ 
    cd build && \
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=ON \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D BUILD_EXAMPLES=ON .. && \
    make -j4 && \
    make install && \ 
    ldconfig

RUN ln -s /usr/local/lib/python3.4/site-packages/cv2.cpython-34m.so /usr/local/lib/python3.4/site-packages/cv2.so

RUN apt-get -y update
RUN apt-get install -y --fix-missing \
    build-essential \
    cmake \
    gfortran \
    git \
    wget \
    curl \
    graphicsmagick \
    libgraphicsmagick1-dev \
    libatlas-dev \
    libavcodec-dev \
    libavformat-dev \
    libboost-all-dev \
    libgtk2.0-dev \
    libjpeg-dev \
    liblapack-dev \
    libswscale-dev \
    pkg-config \
    python3-dev \
    python3-numpy \
    software-properties-common \
    zip \
    && apt-get clean && rm -rf /tmp/* /var/tmp/*




RUN cd ~ && \
    mkdir -p dlib && \
    git clone -b 'v19.4' --single-branch https://github.com/davisking/dlib.git dlib/ && \
    cd  dlib/ && \
    python3 setup.py install --yes USE_AVX_INSTRUCTIONS

But when I'm doing import cv2, it's giving me the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'cv2'

When I'm doing find / -name "cv.py", I'm getting

/usr/lib/python2.7/dist-packages/cv.py

And for this find / -name "cv2.so", the result is

/usr/local/lib/python3.4/site-packages/cv2.so /usr/local/lib/python2.7/dist-packages/cv2.so /opencv-3.2.0/build/lib/cv2.so

I don't know where I'm making the mistake. Can someone please guide me?

Thank you!

2017-07-04 04:22:27 -0600 commented question Multiple Text Dislay on Images

@berak: No. It's just for local system. I'm first trying to make it on local system before shifting it on docker.

2017-07-04 02:21:10 -0600 asked a question Multiple Text Dislay on Images

Hi,

I'm trying to implement multiple text in a video frame. E.g. the following code just display 1 text for an image. In this code at present I can pass one "name" at a time. I want to pass multiple names. E.g. if 2 people are detected it should pass 2 names.

video_capture = cv2.VideoCapture(0)

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


    # Loop through each face in this frame of video
    faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=5,
    minSize=(30, 30),
    flags=cv2.cv.CV_HAAR_SCALE_IMAGE)

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 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 frame
    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()

Thank you!

2017-07-04 00:44:21 -0600 commented question Installing opencv in docker container

Thanks Berak! I'll consider them.

2017-07-04 00:02:22 -0600 commented question Installing opencv in docker container

Thanks Berak for the comment! Actually opencv is used for reading video file. Actually we are trying objects in video frames. Detection is done by Dlib, but reading the video is done by opencv. I'll try the installation as you suggested. Thanks a lot!

2017-07-03 23:29:28 -0600 commented question Installing opencv in docker container

Yeah :)

Thank you!

2017-07-03 14:28:06 -0600 asked a question Installing opencv in docker container

Hi,

I'm trying to install opencv for this project. In the original dockerfile, they didn't give instructions for installing opencv. The dockerfile portion is follows:

FROM python:3.4-slim

#RUN apt-get -y update
RUN apt-get update && apt-get install -y \ 
    build-essential \
    cmake \
    gfortran \
    git \
    libatlas-base-dev \
    libav-tools  \
    libgtk2.0-dev \
    libjasper-dev \
    libjpeg-dev \
    libopencv-dev \
    libpng-dev \
    libtiff-dev \
    libvtk6-dev \
    pkg-config \
    python-dev \
    python-numpy \
    python-opencv \
    python-pycurl \
    qt5-default \
    unzip \
    webp \
    wget \
    zlib1g-dev 
    #&& apt-get clean && rm -rf /tmp/* /var/tmp/*

RUN mkdir -p ~/opencv cd ~/opencv && \
    wget https://github.com/Itseez/opencv/archive/3.2.0.zip && \
    unzip 3.2.0.zip && \
    rm 3.2.0.zip && \
    cd opencv-3.2.0 && \
    mkdir build && \ 
    cd build && \
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=ON \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D BUILD_EXAMPLES=ON .. && \
    make -j4 && \
    make install && \ 
    ldconfig

RUN ln -s /usr/local/lib/python3.4/site-packages/cv2.cpython-34m.so /usr/local/lib/python3.4/site-packages/cv2.so

RUN apt-get -y update
RUN apt-get install -y --fix-missing \
    build-essential \
    cmake \
    gfortran \
    git \
    wget \
    curl \
    graphicsmagick \
    libgraphicsmagick1-dev \
    libatlas-dev \
    libavcodec-dev \
    libavformat-dev \
    libboost-all-dev \
    libgtk2.0-dev \
    libjpeg-dev \
    liblapack-dev \
    libswscale-dev \
    pkg-config \
    python3-dev \
    python3-numpy \
    software-properties-common \
    zip \
    && apt-get clean && rm -rf /tmp/* /var/tmp/*

RUN cd ~ && \
    mkdir -p dlib && \
    git clone -b 'v19.4' --single-branch https://github.com/davisking/dlib.git dlib/ && \
    cd  dlib/ && \
    python3 setup.py install --yes USE_AVX_INSTRUCTIONS

COPY . /root/face_recognition
RUN cd /root/face_recognition && \
pip install -r requirements.txt && \
python setup.py install

CMD cd /root/face_recognition/examples && \
python recognize_faces_in_pictures.py

But when I'm doing import cv2, it's giving me the error:

Traceback (most recent call last): File "", line 1, in ImportError: No module named 'cv2'

``When I'm doingfind / -name "cv.py"`, I'm getting

/usr/lib/python2.7/dist-packages/cv.py

And for thisfind / -name "cv2.so", the result is

/usr/local/lib/python3.4/site-packages/cv2.so /usr/local/lib/python2.7/dist-packages/cv2.so /opencv-3.2.0/build/lib/cv2.so

I don't know where I'm making the mistake. Can someone please guide me?

Thank you!

2017-06-29 00:15:29 -0600 received badge  Enthusiast
2017-06-22 05:20:32 -0600 commented question Error in Face Recognition Algorithm

I learned how to debug in these circumstances! Thank you!

2017-06-22 04:43:22 -0600 commented question Error in Face Recognition Algorithm

@berak: There's a folder which has some corrupted jpg files. When I tried to follow your instruction, I found for a particular folder the code was failing. Once removed that folder, it's working perfectly. Thanks a lot for your suggestion!

2017-06-22 04:16:30 -0600 commented question Error in Face Recognition Algorithm

@berak: They are jpg images of size around 10KB. The folder structure celebrities\adam_brody,celebrities\al_gore, celebrities\liv_tyler, etc. I'm using the same structure with my own dataset downloaded from internet, and it's working fine. But with celebrities dataset it's not. Can't figure out why it should be. It's a very standard dataset.

2017-06-22 04:06:48 -0600 asked a question Error in Face Recognition Algorithm

Hi,

I'm using the following code for face recognition. It's working fine for most of the image datasets that I've. But when I'm using this dataset (15.8 MB one), I'm getting the error:

RuntimeError: Unsupported image type, must be 8bit gray or RGB image.

My code is the following:

import numpy as np
import dlib
import cv2
import os
import PIL.Image
import math
import operator

predictor_path = "C:/Users/userpath/shape_predictor_68_face_landmarks.dat" 
rootdir = 'C:/Users/userpath/celebrities'
font = cv2.FONT_HERSHEY_SIMPLEX
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))

recognizer = cv2.face.createEigenFaceRecognizer()

images = []
labels = []
labels_index = []

def getFaces(frame):
    dets = detector(frame, 1)
    return dets

def highlightFaces(frame, faces):
    for face in faces:
        cv2.rectangle(frame, (face.left(), face.top()), (face.right(), face.bottom()), (255,255,255), 1, 0)
    return frame

def markFace(frame, shape):
    cv2.circle(frame, (shape.parts()[0].x, shape.parts()[0].y), 2, (255,255,255), -1)
    cv2.circle(frame, (shape.parts()[8].x, shape.parts()[8].y), 2, (255,255,255), -1)
    cv2.circle(frame, (shape.parts()[16].x, shape.parts()[16].y), 2, (255,255,255), -1)
    cv2.circle(frame, (shape.parts()[18].x, shape.parts()[18].y), 2, (255,255,255), -1)
    cv2.circle(frame, (shape.parts()[24].x, shape.parts()[24].y), 2, (255,255,255), -1)
    cv2.circle(frame, (shape.parts()[30].x, shape.parts()[30].y), 2, (255,255,255), -1)
    cv2.circle(frame, (shape.parts()[36].x, shape.parts()[36].y), 2, (255,255,255), -1)
    cv2.circle(frame, (shape.parts()[39].x, shape.parts()[39].y), 2, (255,255,255), -1)
    cv2.circle(frame, (shape.parts()[42].x, shape.parts()[42].y), 2, (255,255,255), -1)
    cv2.circle(frame, (shape.parts()[45].x, shape.parts()[45].y), 2, (255,255,255), -1)
    return frame

def cropFace(frame, shape):
    #    points = shape.parts()
#    y1 = points[18].y if points[18].y < points[24].y else points[24].y
#    y2 = points[8].x
#    x1 = points[0].x
#    x2 = points[16].x
#
#    face = frame[y1:y2, x1:x2]
    face = frame[0:200, 0:200]
    face = cv2.resize(face, (200, 200))
    #cv2.imshow("face", face)
    return face

def centerPoint(p1, p2):
    x1, y1 = p1.x, p1.y
    x2, y2 = p2.x, p2.y
    return (x1 + (x2 - x1)* .5, y1 + (y2 - y1) * .5)

# returns the center position of right eye as tuple
def rightEye(shape):
    p1 = shape.parts()[36]
    p2 = shape.parts()[39]
    return centerPoint(p1, p2)

# returns the center position of right eye as tuple
def leftEye(shape):
    p1 = shape.parts()[42]
    p2 = shape.parts()[46]
    return centerPoint(p1, p2)

# Find angle
def faceAngle(shape):
    p1 = shape.parts()[0]
    p2 = shape.parts()[16]
    x1, y1 = p1.x, p1.y
    x2, y2 = p2.x, p2.y
    dx,dy = x2-x1,y2-y1

    rads = -math.atan2(dy, dx)
    return math.degrees(rads)

#rotate image around a point
def rotateImage(image, point, angle):
    rows,cols = image.shape 
    M = cv2.getRotationMatrix2D(point,angle * -1,1 ...
(more)
2017-06-22 02:25:52 -0600 commented question Face Recognition using Dlib

Thanks Berak! This information is also useful. Now I can try other options.

2017-06-22 02:20:44 -0600 commented question Face Recognition using Dlib

Thanks berak! But I was looking for python example. It seems we still don't have python option for face recognition in Dlib

2017-06-22 02:04:49 -0600 received badge  Editor (source)
2017-06-22 02:04:22 -0600 asked a question Face Recognition using Dlib

Hi,

I know this exactly not an Dlib forum. But since most of the people who visited this site have experience with image processing, so thought might get some help here.

I'm working on face recognition in a video file or real-time. In Opencv, there's an option like "createLBPHFaceRecognizer" (we have couple of others in OpenCV) to train on our images before prediction. My question is, is there similar functionality in Dlib to train on images before prediction on new image?

2017-06-16 01:38:39 -0600 received badge  Supporter (source)
2017-06-16 01:38:30 -0600 received badge  Scholar (source)
2017-06-16 01:38:23 -0600 commented answer Training and Test images must be of equal size

Thanks Berak! Your answer solved the problem.Thanks a lot!

2017-06-16 00:08:17 -0600 asked a question Training and Test images must be of equal size

I'm trying to do face recognition for my project similar to this. But I need to detect it in a video. So I'm taking a video (Friends Video) and take some images from this video for training purpose. I'm using the following code to get the frames:

import cv2
vidcap = cv2.VideoCapture('pathToFolder/Friends - Bad monkey, Hot girls and Phoebe saves the monkey.mp4')
success,image = vidcap.read()
count = 0
success = True
while success:
  success,image = vidcap.read()
  print('Read a new frame: ', success)
  cv2.imwrite("pathToFolder/Friends/frame%d.jpg" % count, image)     # save frame as JPEG file
  count += 1

And then running the following code:

import cv2, sys, numpy, os
size = 3
#fn_haar = 'haarcascade_frontalface_default.xml'
fn_dir = 'pathToFolder/Friends_Train'

# Part 1: Create fisherRecognizer
print('Training...')

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

# Get the folders containing the training data
for (subdirs, dirs, files) in os.walk(fn_dir):

    # Loop through each folder named after the subject in the photos
    for subdir in dirs:
        names[id] = subdir
        subjectpath = os.path.join(fn_dir, subdir)

        # Loop through each photo in the folder
        for filename in os.listdir(subjectpath):

            # Skip non-image formates
            f_name, f_extension = os.path.splitext(filename)
            if(f_extension.lower() not in
                    ['.png','.jpg','.jpeg','.gif','.pgm']):
                print("Skipping "+filename+", wrong file type")
                continue
            path = subjectpath + '/' + filename
            lable = id

            # Add to training data
            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.face.createFisherFaceRecognizer()
model.train(images, lables)




# Part 2: Use fisherRecognizer on camera stream
haar_cascade = cv2.CascadeClassifier('C:/opencv-3.2.0/data/haarcascades/haarcascade_frontalface_default.xml')

webcam = cv2.VideoCapture('pathToFolder/Friends - Bad monkey, Hot girls and Phoebe saves the monkey.mp4')
while True:

    # Loop until the camera is working
    rval = False
    while(not rval):
        # Put the image from the webcam into 'frame'
        (rval, frame) = webcam.read()
        if(not rval):
            print("Failed to open webcam. Trying again...")

    # Flip the image (optional)
    #frame=cv2.flip(frame,1,0)

    # Convert to grayscalel
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Resize to speed up detection (optinal, change size above)
    mini = cv2.resize(gray, (int(gray.shape[1] / size), int(gray.shape[0] / size)))

    # Detect faces and loop through each one
    faces = haar_cascade.detectMultiScale(mini)
    for i in range(len(faces)):
        face_i = faces[i]

        # Coordinates of face after scaling back by `size`
        (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)

        # [1]
        # Write the name of recognized face
        cv2.putText(frame,
           '%s - %.0f' % (names[prediction[0]],prediction[1]),
           (x-10, y-10), cv2.FONT_HERSHEY_PLAIN,1,(0, 255, 0))

    # Show the image and check ...
(more)