Ask Your Question

marcosbontempo's profile - activity

2020-01-13 05:58:45 -0600 received badge  Popular Question (source)
2017-10-29 06:43:42 -0600 asked a question Difference between two images light independent

Difference between two images light independent Hello, I'm getting the difference between two images using the absdiff

2017-04-25 08:00:20 -0600 asked a question Face detection looking down

Hello,

Does anybody have an idea of how detect faces when the person is looking down? I already tested a lot of haar cascades but they only work when the person is looking straight to the camera.

Any tip will be very helpful, Thanks

2016-10-28 06:52:08 -0600 asked a question FindContours returing only one contour for two objects

Hello,

I'm trying to count people with a motion detection code. It works fine if only one person is walking but, when they walk side by side, it counts two as one. I think the problem is in findContours, because it's returning only one contour.

Here is my code:

import cv2
import numpy as np

c = cv2.VideoCapture(0)
_,f = c.read()

avg2 = np.float32(f)

while(1):
    _,f = c.read()

    cv2.accumulateWeighted(f,avg2,0.1)
    res2 = cv2.convertScaleAbs(avg2)
    gray_res = cv2.cvtColor(res2, cv2.COLOR_BGR2GRAY)

    # Get difference between frames 
    gray = cv2.cvtColor(f, cv2.COLOR_BGR2GRAY)

    # compute the absolute difference between the current frame and background
    frameDelta = cv2.absdiff(gray_res, gray)
    thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]

    # dilate the thresholded image to fill in holes, then find contours
    # on thresholded image
    thresh = cv2.dilate(thresh, None, iterations=2)
    (cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    # loop over the contours
    for cnt in cnts:
    # compute the bounding box for the contour, draw it on the frame,
    # and update the text
        (x, y, w, h) = cv2.boundingRect(cnt)
        cv2.rectangle(f, (x, y), (x + w, y + h), (0, 255, 0), 2)

    cv2.imshow('img',f)
    cv2.imshow('avg2',res2)
    cv2.imshow('delta',frameDelta)

cv2.destroyAllWindows()
c.release()

And here is a image of what's happening:

image description

I already tried to use the size of the contour to check if there are two persons but sometimes the size of one person is equal of the size of two.

Does anybody have an idea of how to count two people if they are walking together? I was thinking about counting the heads, but I cannot find any way of doing that. Sometimes they walk so close that there is no space between their bodies, only between their heads. Do I have to check inside of the contour?

Any tip will be very helpful,

Thanks

2016-10-26 07:47:56 -0600 commented question FaceRecognizer doubts

I'm using version 2.4.9 and yes, I can create the instance.

2016-10-25 14:20:06 -0600 asked a question FaceRecognizer doubts

Hello,

I'm developing an application that uses the OpenCV FaceRecognizer Java class to verify if a face is in a database of images. It works if I run my code only one time, but I want to update the database and remake the training multiple times. I'm having some doubts about doing this:

  • If I need to repeat the training, do I have to create the object again like the code below? How can I reset the FaceReconizer object?

        faceRecognizer = new FaceRecognizer();
        faceRecognizer = createEigenFaceRecognizer();
        faceRecognizer.train(images, labels);
    
  • I have a database with images of 5 different people. How do I have to pass these images to faceRecognizer.train? What do I have to insert in the labels variable?

  • I'm having doubts about how to read the result of faceRecognizer.predict. In my case I only want to check if a face is in the database. How can I read the returned variables (label and confidence) to determine it?

Sorry for the newbie questions but I'm really stuck and I cannot find any documentation about it :(

Any tip will be very helpful,

Thanks

2016-09-30 15:48:06 -0600 asked a question Android findContours returning too many contours

Hello,

I'm trying to find the contours of the camera frame in a Android app. Here is the code:

Imgproc.Canny(src, src, 50, 200);
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
// find contours:
Imgproc.findContours(src, contours, hierarchy, Imgproc.RETR_TREE,Imgproc.CHAIN_APPROX_SIMPLE);
for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
    Imgproc.drawContours(src, contours, contourIdx, new Scalar(0, 0, 255), -1);
}

Here is an example of frame:

image description

It's working but my problem is that findContour is returning too many contours. Sometimes it returns more than 3000 contours and it takes too much time to draw them.

In the frame there is a person. I would like to get only one contour with the person instead of many of them in each line of the face.

Is there a way to approximate the little contours in a only one with the whole object? I'm looking for a way to reduce the number of contours, getting only the biggest of them.

Any tip will be very helpful,

Thanks

2016-09-28 09:29:04 -0600 commented question OpenCV Android absdiff not working

@berak Did this function changes accuImg type? I thought it would dump the result to img.

2016-09-28 09:01:05 -0600 commented question OpenCV Android absdiff not working

@berak Sorry, I copied the wrong code. It's already edited.

2016-09-28 08:44:57 -0600 asked a question OpenCV Android absdiff not working

Hello,

I want to create a motion detector in a OpenCV Android app.

First I accumulate the background with this class:

private Mat                    mRgba;
private Mat                    mGray;
private Mat                    mBackground;
private Mat                    mDifference;

public Mat accumulateImageBG(Mat img, int type){
    if (accuImg==null){//code snipit from berak's answer
        accuImg = Mat.zeros(img.size(), type);
    }

    if (mDifference==null){//code snipit from berak's answer
        mDifference = Mat.zeros(img.size(), CvType.CV_8UC1);
    }

    img.convertTo(img, type);
    Imgproc.accumulateWeighted(img, accuImg, 0.1);
    Core.convertScaleAbs(accuImg, img);
    return img;
}

And then I want to calculate the difference between the background and the camera frame. I tried this code:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

    mRgba = inputFrame.rgba();//in:CV_8UC4 out:CV_32FC4
    mGray = inputFrame.gray();//in:CV_8UC1 out:CV_32F

    //be sure to specify conversion type with matching # of channels as input image!
    mBackground = accumulateImageBG(mGray, CvType.CV_32F);

    // Subtract the work image frame from the scaled image average
    Core.absdiff(mBackground, mGray, mDifference);

    return mDifference;
}

But it's always returning a blank frame. I think there is a problem with my absdiff code. Does anybody know if I did something wrong? I already tested with 3.1.0, 3.0.0 and 2.4.11 versions.

Any tip will be very helpful,

Thanks

2016-09-21 08:46:32 -0600 commented question MatchParent not working with diferent angles and sizes

@Eduardo I'm having problems with the image quality and the focus because I need to detect the object in movement. Is there a better detection method for objects in movement?

2016-09-21 08:03:17 -0600 asked a question MatchParent not working with diferent angles and sizes

Hello,

I'm using this template to find a juice box in a camera capture:

image description

But I'm not getting good results. It only detects the box in this angle and size. Is there a better way to find a object in diferent angles and size?

I already used a Haar Cascade Classifier. Is it better for video applications? Are there another methods?

Any tip will be very helpful,

Thanks

2016-09-09 15:12:02 -0600 asked a question OpenCV Python detect camera's trepidation

Hello,

Is there a python code that can detect the trepidation of the camera? I have no idea how can I do it :(

Any tip will be very helpful,

Thanks

2016-08-10 12:37:08 -0600 commented question Counting detected objects with Haar Cascade

I'm thinking if there are some parameters that differ one person from the others. For example, if the distance between my eyes is 10 pixels, my algorithm can realize that I'm still in the video and don't count me again. What do you think @berak? Do you if there is a parameter or operation that I can use, like a histogram?

2016-08-10 12:18:14 -0600 commented question Counting detected objects with Haar Cascade

Is it too much hard? There are lot of videos: https://www.youtube.com/watch?v=qDK6n...

2016-08-10 12:10:52 -0600 commented question Counting detected objects with Haar Cascade

My main doubt is how to count only one time a object while it stays on the video. In all my attempts I counted multiple times the same object.

2016-08-10 12:05:02 -0600 commented question Counting detected objects with Haar Cascade

Sorry, my mistake @berak. You're right, I want to count the objects over several frames.

2016-08-10 12:00:25 -0600 commented question Hardware requirements to run Opencv in a Android platform

Thanks for your answer, @StevenPuttemans! I was worried about buying a smartphone with insufficient resources but now I think I can make the choice :)

2016-08-10 11:54:59 -0600 asked a question Counting detected objects with Haar Cascade

Hello,

I'm using a Haar Cascade classifier to identify in a camera capture. Now I also want to count the detected faces, but I'm having some logical problems to do it.

First I tried to add the number of the detected faces in every frame. It didn't work because the same face is added again after a new frame. Other problem is that the Cascade sometimes fails and the face is not detected. I don't want to count these instabilities or detections that happen in only one frame.

Does anybody know how to implement a reliable algorithm to count objects detected by a Haar Cascade classifier?

Any tip will be very helpful,

Thanks

2016-08-09 14:43:03 -0600 asked a question Hardware requirements to run Opencv in a Android platform

Hello,

I'm developing some apps using Haar Cascade for Android and I want to know which is the cheaper smartphone that can execute them. Does anybody know what are the minimum hardware requirements to run OpenCV in a Android platform? I searched in the docs but I couldn't find.

Any tip will be very helpful, Thanks.

2016-08-09 14:24:35 -0600 received badge  Enthusiast
2016-08-08 13:06:13 -0600 answered a question General People Cascade Classifier

Thanks for your help @sturkmen and @berak. It would be easier to me to put the camera in that position (because of the coverage area) but I decided to change it so I can capture the head.

2016-08-04 20:04:07 -0600 commented question General People Cascade Classifier

@sturkmen I added the image to the question :) I think I'm having problems because the camera is not capturing the head

2016-08-04 17:13:10 -0600 commented question General People Cascade Classifier

Thanks for your answer @sturkmen! I tried using the OpenCV ready classifiers, but they didn't work. I think it's because the position of my camera.

Here is my image: http://i.imgur.com/aq1qWXL.png

Do you know if there is a classifier that could work?

Thanks

2016-08-04 15:09:20 -0600 asked a question General People Cascade Classifier

Hello,

I'm training a Haar Cascade Classfier to identify people based on a set of samples. It works with the people from the pictures, but how can I assure that the classifier will work with different people? And what if they use different types of clothes?

Is there a way to produce a general Cascade Classifier that can identify every kind of people?

Here is the image I'm using:

image description

Any tip will be very helpful,

Thanks

2016-07-15 09:37:03 -0600 asked a question Haar Cascade instability

Hello,

I trained my Cascade Classifier to identify an object. It works, but not in all frames.

Here is a frame missing one object:

image description

And here is other frame with all the objects:

image description

The images are almost the same. When I apply the cascade in a video, I can see the moments that the objects are not identified and it looks incomplete. Does anybody know how can I identify all the objects in all the frames, so the green rectangle will be permanent? Why it is happening, since the images are almost the same?

Any tip will be very helpful,

Thanks.

2016-06-09 07:52:48 -0600 received badge  Editor (source)
2016-06-09 07:52:38 -0600 asked a question Running OpenCV in a Cloud Computing server

Hello,

Did anybody already run an OpenCV application in a Cloud Computing host? Do I need to expect too much differences between an usual computer? Does anybody suggests a provider for running OpenCV softwares? I wanna know about your experiences when using Cloud Computing servers.

Any tip will be very helpful,

Thanks.

2016-05-26 12:14:06 -0600 received badge  Student (source)
2016-05-26 12:10:40 -0600 commented answer Haar cascade training

Thanks for warning me @StevenPuttemans! Almost everything that I read about haar cascade traing uses this link. I'll read the book's chapter as you suggested.

  1. I increased the number of images to 50 positives and 150 negatives. Do you think it is enough? Is there a magical number recommended?
  2. I changed the ratio and now my results are much better.
  3. I uploaded my samples: https://mega.nz/#!V5txVYaB!4DxsN_Jxw1.... Could you please take a look?

My model is working better now with your advices, but it sometimes does not identify positive images. I'm facing this issue with black cars. Do you have any idea of how can I improve it? I though about adding more black car positive images.

2016-05-25 14:21:33 -0600 received badge  Supporter (source)
2016-05-25 13:51:59 -0600 asked a question Haar cascade training

Hello,

I want to use a haar cascade classifier to detect objects in a image.

I have 18 positive images and 24 negative images. Their size is 50 x 30. With them, I used this command to generate 1500 samples:

perl bin/createsamples.pl positives.txt negatives.txt samples 1500 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 50 -h 30"

After merging, I started the haar cascade training with this command:

opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000 -numNeg 600 -w 50 -h 30 -mode ALL -precalcValBufSize 2048 -precalcIdxBufSize 2048

But it's converging too soon and it hangs in the third state:

PARAMETERS:
cascadeDirName: classifier
vecFileName: samples.vec
bgFileName: negatives.txt
numPos: 1000
numNeg: 600
numStages: 20
precalcValBufSize[Mb] : 2048
precalcIdxBufSize[Mb] : 2048
stageType: BOOST
featureType: HAAR
sampleWidth: 50
sampleHeight: 30
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: ALL

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   1000 : 1000
NEG count : acceptanceRatio    600 : 1
Precalculation time: 36
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|0.00333333|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 7 minutes 8 seconds.

===== TRAINING 1-stage =====
<BEGIN
POS count : consumed   1000 : 1000
NEG count : acceptanceRatio    600 : 0.0812568
Precalculation time: 31
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        0|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 13 minutes 37 seconds.

I used this link as a reference: http://coding-robin.de/2013/07/22/tra....

Does anybody know which parameter can I change to improve the training? Do I need to use more positive or negative images?

Any tip will be very helpful,

Thanks.

2016-05-25 07:02:19 -0600 commented answer Identifying black cars with OpenCV in Python

Thanks for your answer!

Yes, I have each vacancy's ROI. As you suggested, I'm trying the haar cascade solution, according to this link: http://coding-robin.de/2013/07/22/tra...

But, in the haar cascade training, I realized that it's converging too soon:

===== TRAINING 1-stage =====

| N | HR | FA |

| 1| 1| 1|

| 2| 1| 0.3333|

Do you know what is wrong? I assured that the width x heigh ratio is the same of the images. I'm using this command:

opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.95 -maxFalseAlarmRate 0.5 -numPos 1000 -numNeg 600 -w 50 -h 30 -mode ALL -precalcValBufSize 2048 -precalcIdxBufSize 2048

Am I missing any parameter?

2016-05-24 00:53:10 -0600 asked a question Identifying black cars with OpenCV in Python

Hello,

I'm using OpenCV in Python to identify cars in a parking lot. It works fine when the color of the car is different than black.

Here is my code. It basically applies a canny and counts the white points:

cv2.imshow("image", image)
cv2.waitKey()

# Gray scale and blur
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
gray = cv2.bilateralFilter(gray, 5, 10, 10)
blur = cv2.GaussianBlur(gray,(5,5),0)        
cv2.imshow("blur", blur)
cv2.waitKey()

# Apply canny
edged = cv2.Canny(blur, 30, 200)
cv2.imshow("Edged", edged)
cv2.waitKey()

# Result
points = cv2.countNonZero(edged)

Here is the result for a white car:

white car

But the code doesn't work well with the shadows of the others cars:

shadows

And even worst with black cars:

black car

How do I fix this problem? Do I need to change my method? Maybe the canny isn't the best.

I'm using this image of the parking:

parking

Any tip will be very helpful,

Thanks