Ask Your Question

Codacus's profile - activity

2019-05-11 18:43:51 -0600 received badge  Enthusiast
2017-03-28 15:39:04 -0600 answered a question How to refine the edges of an image?
blur = cv2.GaussianBlur(img,(5,5),0)
smooth = cv2.addWeighted(blur,1.5,img,-0.5,0)

this will do the work, you can adjust the kernel size for the blur according to your requirement..

2017-03-28 15:26:37 -0600 answered a question How to convert Keypoints to an argument for findhomography()?
    tp=[]
    qp=[]
    for m in goodMatch:
        tp.append(trainKP[m.trainIdx].pt)
        qp.append(queryKP[m.queryIdx].pt)
    tp,qp=np.float32((tp,qp))
    H,mask=cv2.findHomography(tp,qp,cv2.RANSAC,3.0)

I think this will work, source

2017-02-28 16:26:53 -0600 commented question How to read a MP4 file with OpenCV-Python

try using cv2.waitKey(10) instead of cv2.waitKey(1)

2017-02-28 09:26:04 -0600 commented question I am unable to get OpenCV to run in python.

I was having a doubt that you are pasting cv2.pyd in one version of the python and when using python you are running the other version..

2017-02-28 08:54:24 -0600 received badge  Supporter (source)
2017-02-24 04:44:01 -0600 answered a question Help: Face Recognition using LBP confused with unknown Faces

As already mentioned in the code you can use model->predict(testSample, predictedLabel, confidence); to get the predictedLabel and confidence, the confidence variable will give you the estimate of how accurate the prediction is. the lesser the value to more accurate the prediction is.

So you can use it like this way

if(confidence<50){
    // put the predictedLebel as a detected face
}
else{
    // put the Unknown as a detected face
}

Now you can play with this value 50 to work best for you.

Here is a series of articles in python if you are interested for face recognition for known and unknown faces

2017-02-24 04:27:06 -0600 answered a question How to recognise multiple faces and create DBMS for the same?

OpenCV has many face recognizer built-in like LBPHFaceRecognizer or EigenFaceRecognizer,

for your project you will need a cascade classifier to first detect the face regions and the use those recognizer to recognize the person, here is a series of article you can follow to make your recognizer,

Hope this will help

2017-02-23 11:02:13 -0600 answered a question reduce processing time of webcam capture

One thing you can do is you can run a separate thread for grabbing the images from the video capture object, and put that captured images in a queue, and from the main thread get a frame from the queue and do your processing.

So while the main thread is processing the image for 25ms, the grabber thread will be able to grab (25/9)=2 frames in the queue ready for the main thread to process and the main thread wont have to wait 9ms for image to be captured.

this will completely remove that 9ms time that was being added to your total time

So right now its like : grab frame(9ms)+ process(25ms)=total time (34ms)

with a separate thread running:

grabber thread:->grab(9ms)--->grab(9ms)------->grab(9ms)----->grab(9ms)->-

main thread: ---> wait(9ms)->getFrame()->--Process------(25ms)---getFrame().... total time for one process cycle is 25ms

so this way the main thread will only wait 9ms in the beginning for the first frame and wont have to wait again anymore

Update: Did some testing in python by myself to see how much it improves the processing in practical, and this is the result

import threading
import time
import Queue
import cv2
frames = Queue.Queue(5)

class ImageGrabber(threading.Thread):
    def __init__(self, ID):
        threading.Thread.__init__(self)
        self.ID=ID
        self.cam=cv2.VideoCapture(ID)
        self.cam.set(3,1280) # just to increase capture time
        self.cam.set(4,1024) # just to increase capture time
        self.runFlag=True

    def run(self):
        print "sub started"
        global frames
        while self.runFlag:
            ret,frame=self.cam.read()
            frames.put(frame)
            time.sleep(0.01)
        self.cam.release()
    def stop(self):
        self.runFlag=False



##------------------------##
## Some random processing ##
## -----------------------##

def Process(img):
    #img1=cv2.Canny(img,100,200)
    img2=cv2.blur(img,(5,5))

##------------------------##
##    without threading   ##
##------------------------##

cam=cv2.VideoCapture(0)
cam.set(3,1280) # just to increase capture time
cam.set(4,1024) # just to increase capture time
ret,img=cam.read()# to ignore the lag of first capture
sumTime=0
i=0
while i<30:
    i=i+1
    start=time.time()
    ret,img=cam.read()
    capTime=time.time()
    Process(img)
    end=time.time()
    sumTime=sumTime+end-start
    print end-start, "capture time=",capTime-start

print "avarage time without multithread=",sumTime/30    
cam.release()


##------------------------##
##     with threading     ##
##------------------------##
grabber = ImageGrabber(0)
grabber.start()
i=0
sumTime=0
while i<30:
    if(not frames.empty()):
        i=i+1
        start=time.time()
        Currframe=frames.get()
        Process(Currframe)
        end=time.time()
        sumTime=sumTime+end-start
        print end-start
print "avarage time with multithread=",sumTime/30    
grabber.stop()
grabber.join()

And this is the output

0.108999967575 capture time= 0.0929999351501
0.0569999217987 capture time= 0.0420000553131
0.0190000534058 capture time= 0.00499987602234
0.055999994278 capture time= 0.0389997959137
0.0340001583099 capture time= 0.0210001468658
0.0820000171661 capture time= 0.069000005722
0.0350000858307 capture time= 0.0199999809265
0.0660002231598 capture time= 0.0530002117157
0.0350000858307 capture time= 0.0209999084473
0.0629999637604 capture time= 0.0479998588562
0.0239999294281 capture time= 0.00499987602234
0.0440001487732 ...
(more)
2017-02-22 13:53:42 -0600 received badge  Editor (source)
2017-02-22 13:52:58 -0600 answered a question python frame grabbing from ip camera and process in a different thread

This is an implementation that I used once

python has a thread safe queue which can be used for this purpose

hope this will help

import threading
import time
import Queue
import cv2
frames = Queue(10)

class ImageGrabber(threading.Thread):
    def __init__(self, ID):
        threading.Thread.__init__(self)
        self.ID=ID
        self.cam=cv2.VideoCapture(ID)

    def Run(self):
        global frames
        while True:
            ret,frame=self.cam.read()
            frames.put(frame)
            time.sleep(0.1)


class Main(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        global frames
        while True:
            if(not frames.empty()):
                self.Currframe=frames.get()
            ##------------------------##
            ## your opencv logic here ##
            ## -----------------------##


grabber = ImageGrabber(0)
main = Main()

grabber.start()
main.start()
main.join()
grabber.join()
2017-02-22 12:49:19 -0600 answered a question How to grab pixel coordinates of detected face/eyes?

(rect[0], rect[1]) yes those are exactly upper left and,.. , (rect[2], rect[3]) are the lower left corners..

you can just do the following

xFaceCenter=(rect[2]-rect[0])/2
yFaceCenter=(rect[3]-rect[1])/2

and now you have the height and width of the image frame lets say h,w then you can easily use

dy=(h/2)-yFaceCenter
dx=(w/2)-xFaceCenter

So you now just have to make these dy and dx values to be zero by changing the horizontal and vertical servo angle accordingly

2017-02-22 12:36:42 -0600 commented question I am unable to get OpenCV to run in python.

you might be having two python installation.. try to remove all python from control panel as well as from the folder where you are pasting cv2.pyd and then create a clean python installation.. try after that

2017-02-22 12:24:39 -0600 answered a question image sampling and its implementation in opencv

Well if you are using python, you can use "cv2.resize()"

subA = cv2.resize(A, (128,128), interpolation = cv2.INTER_AREA)

subA' = cv2.resize(A', (128,128), interpolation = cv2.INTER_AREA)

if both A,A' are same in dimension then both sub-sampled image will have same pixel operation on it

2017-02-22 12:24:38 -0600 commented question Computing disparity map is very SLOW!

I also did the same, lower resolution images around 600x400 (approx cont remember) also posted https://www.youtube.com/watch?v=T77i_P-7otM (Vlog) its not very clear map but works for realtime

2017-02-08 07:25:42 -0600 answered a question How do i resize my training images in fisher faces ?

You can use, "cv2.resize(image, (height, width))" this function to resize the training images just before you feed it to the recognizer

2017-02-05 05:43:20 -0600 answered a question Opencv LBPHFaceRecognizer Train data in Python

recognizer.save("filename.yml"), file name is in quote and to load the trained recognizer you will need recognizer.load("filename.yml")..