Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed #10

Open
7 of 10 tasks
tpb1908 opened this issue Feb 8, 2017 · 12 comments
Open
7 of 10 tasks

Speed #10

tpb1908 opened this issue Feb 8, 2017 · 12 comments
Assignees

Comments

@tpb1908
Copy link
Owner

tpb1908 commented Feb 8, 2017

  • When Dlib is on, render frame takes 170ms, even when the webcam is off, not sure what is going on
  • Webcam render call takes anywhere from 6 to 12 ms
  • next_frame takes 50-60 ms, which is far too long (Of which 99.5% is reading, the rest if is flipping)
  • FaceHighlighter takes 0.1ms
  • Counting Line also takes 0.1 ms
  • Eye highlighter takes 0.03ms
  • Info takes 0.005 ms
  • FPS takes 0.001 ms
  • Movement Vector takes 0.3ms
  • Recolour takes 0.4 ms

Different types of detection can still be split into separate threads.

@tpb1908 tpb1908 self-assigned this Feb 8, 2017
@zoeyfyi
Copy link
Collaborator

zoeyfyi commented Feb 9, 2017

Just did some more profiling

Image.fromarray(frame) 1.10220909119
ImageTk.PhotoImage(image=image) 1.4271736145
self._widget.imgtk = tkimage 0.0178813934326
self._widget.configure(image=tkimage) 10.6511116028

13ms to copy a frame to the screen is completely unacceptable! Going to need to look into a better ui library or something.

@tpb1908
Copy link
Owner Author

tpb1908 commented Feb 9, 2017

Mine takes 6 to 12ms to render.
57ms to read frame (Twice as long as the college PC).

DLib also screws everything up.
Read frame drops to 3ms, but render increases to 190ms.

@tpb1908
Copy link
Owner Author

tpb1908 commented Feb 9, 2017

We have PyQt and PyGTK

@tpb1908
Copy link
Owner Author

tpb1908 commented Feb 9, 2017

Just tested disabling the thread.
If I never start the thread, my webcam feed is still only 15fps, so I have some sort of problem there.

@zoeyfyi
Copy link
Collaborator

zoeyfyi commented Feb 9, 2017

Well we know read frame is cv2, so we can perhaps replace that. And we should expect face detection to take much longer however it shouldn't slow the live webcam feed.

@tpb1908
Copy link
Owner Author

tpb1908 commented Feb 9, 2017

Apparently PyGame has camera bindings http://stackoverflow.com/a/11094891/4191572

@zoeyfyi
Copy link
Collaborator

zoeyfyi commented Feb 9, 2017

Just pushed some benchmarks, this is what I got at 3000 samples:

Tkinter
image = Image.fromar            1.12737043699
tkimage = ImageTk.Ph            1.62594970067
label.imgtk = tkimag            0.0327325661977
label.configure(imag            9.32932750384
Total:                          12.1153802077
pyqt
image = QImage(frame            2.99918651581
pixmap = QPixmap.fro            0.566709836324
label.setPixmap(pixm            0.0311887264252
Total:                          3.59708507856

Over 3 times faster!

@tpb1908
Copy link
Owner Author

tpb1908 commented Feb 9, 2017

I got similar

Tkinter

image = Image.fromar 0.900962352753
tkimage = ImageTk.Ph 1.52412414551
label.imgtk = tkimag 0.0907230377197
label.configure(imag 5.3230547905
Total: 7.83886432648

pyqt

image = QImage(frame 2.30165958405
pixmap = QPixmap.fro 0.319924354553
label.setPixmap(pixm 0.0174856185913
Total: 2.63906955719

The configure really takes ages in tkinter.

@tpb1908
Copy link
Owner Author

tpb1908 commented Feb 9, 2017

I'm still trying to found out why my FPS is capped.
I just used the old camera test

import time

import cv2

cap = cv2.VideoCapture()

print(cap.open(0))

while True:
    start = time.time()
    ret, frame = cap.read()

    cv2.imshow("Image", frame)
    k = cv2.waitKey(33)
    if k != -1:
        break
    print("FPS = " + str((1.0/(time.time()-start))))

cv2.destroyAllWindows()
cap.release()

Which still gives 15 fps regardless of what I pass to cap.set(cv2.cv.CV_CAP_PROP_FPS, fps)

@zoeyfyi
Copy link
Collaborator

zoeyfyi commented Mar 3, 2017

By reducing dlibs input size it runs almost as fast as cv2 but way more accurate. I haven't tested it with a webcam but on the sample video its about 18 FPS.

@zoeyfyi
Copy link
Collaborator

zoeyfyi commented Mar 3, 2017

Also looking into GPU acceleration, it only seems to work with CUDA so it would be useless for the laptop.

@tpb1908
Copy link
Owner Author

tpb1908 commented Mar 3, 2017

Nice, DLib is actually much less CPU intensive. It uses 10%, so less than one core, while CV2 gets up to about 60% usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants