Ask Your Question

pradeepln's profile - activity

2019-12-22 23:52:14 -0600 received badge  Popular Question (source)
2018-08-10 15:16:01 -0600 received badge  Famous Question (source)
2017-10-07 02:27:26 -0600 received badge  Notable Question (source)
2016-11-17 03:12:53 -0600 received badge  Popular Question (source)
2015-11-17 00:01:13 -0600 received badge  Enthusiast
2015-11-13 04:25:25 -0600 commented question Insufficient memory error

Thank you berak..

2015-11-12 23:24:46 -0600 commented question Insufficient memory error

It is related to opencv as I use lot of opencv functions inside preprocessing function. This is how I am allocating the 2D array...

    int** lp = 0;
lp = new int*[img.cols];

for (int j = 0; j < img.cols; j++)
{
    lp[j] = new int[2];
    for (int i = (img.rows - 1); i >= 0; i--)
    {
        if (img.at<uchar>(i, j) == 0)
        {
            //cout << i << j << endl;
            lp[index][0] = j;
            lp[index][1] = i;
            index++;
            break;
        }
    }
}
2015-11-11 22:26:13 -0600 asked a question Insufficient memory error

This is my code, where it loops over a folder which has 745 images. It loops over every image and deoes comparison with the 745 images in the same folder and writes to a .txt file. So it is about 5,55,000 odd computations. I am releasing the memory allocated to images and the pointer arrays as and when it is no longer required but still I am running out of memory. What could be the reason? How to solve this?

int main(int argc, char *argv[]) {

high_resolution_clock::time_point t1 = high_resolution_clock::now();

int  lp, up, vp, all, preprocessImage, displayResults;
float lpThreshold, upThreshold, vpThreshold;

string configFile = argv[1];

ifstream fin(configFile);
string line;
istringstream sin;


while (getline(fin, line)) {
    sin.str(line.substr(line.find("=") + 1));
    if (line.find("preprocessImage") != std::string::npos) {
        sin >> preprocessImage;
    }
    else if (line.find("flaglp") != std::string::npos) {
        sin >> lp;
    }
    else if (line.find("flagup") != std::string::npos) {
        sin >> up;
    }
    else if (line.find("flagvp") != std::string::npos) {
        sin >> vp;
    }
    else if (line.find("all") != std::string::npos) {
        sin >> all;
    }
    else if (line.find("lpThreshold") != std::string::npos) {
        sin >> lpThreshold;
    }
    else if (line.find("upThreshold") != std::string::npos) {
        sin >> upThreshold;
    }
    else if (line.find("vpThreshold") != std::string::npos) {
        sin >> vpThreshold;
    }
    else if (line.find("displayResults") != std::string::npos) {
        sin >> displayResults;
    }
    sin.clear();
}

std::cout << "Configuration:" << endl;
std::cout << "----------------" << endl;

std::cout << "preprocessImage: " << preprocessImage << std::endl;
std::cout << "lp: " << lp << std::endl;
std::cout << "up: " << up << std::endl;
std::cout << "vp: " << vp << std::endl;
std::cout << "all: " << all << std::endl;
std::cout << "displayResults: " << displayResults << std::endl;
std::cout << "lpThreshold: " << lpThreshold << std::endl;
std::cout << "upThreshold: " << upThreshold << std::endl;
std::cout << "vpThreshold: " << vpThreshold << std::endl;
std::cout << " " << endl;

int** lp1 = nullptr;
int** up1 = nullptr;
int** vp1 = nullptr;

int** lp2 = nullptr;
int** up2 = nullptr;
int** vp2 = nullptr;

int lp1Length, lp2Length, up1Length, up2Length, score = 0;
Mat img1, img2, inv1, inv2;
float d1, d2, d3;
int count = 1;

ofstream myfile;
myfile.open("EV_all_10_10_0.7.txt");
myfile << " ,";
vector<cv::String> fn1;
glob("preprocessed_cpp/*.jpg", fn1, false);
size_t count1 = fn1.size();

for (size_t i = 0; i < count1; i++)
{
    string name = fn1[i];
    int slashPos = name.find("\\");
    name = name.substr(slashPos + 1);
    int jpgPos = name.find(".jpg");
    name = name.substr(0, jpgPos);
    myfile << name;

    if (i == (count1 - 1))
    {
        myfile << "\n";
    }
    else
    {
        myfile << ",";
    }


}




for (size_t i = 0; i < count1; i++)
{

    string name = fn1[i];
    int slashPos = name.find("\\");
    name = name.substr(slashPos + 1);
    int jpgPos = name.find(".jpg");
    name = name.substr(0, jpgPos);
    myfile << name;
    myfile << ",";


    img1 = imread(fn1[i], 0);

    if (preprocessImage)
    {
        img1 = preProcess(img1);
    }

    if (lp)
    {
        lp1 = findLowerPixels(img1);
        lp1Length = index;

    }

    if (up)
    {
        up1 = findUpperPixels(img1);
        up1Length = index;
    }

    if (vp)
    {
        inv1 = 255 - img1;
        thinning(inv1);

        vp1 = verticalProjection(inv1);
    }


    if (all)
    {
        lp1 = findLowerPixels(img1);
        lp1Length = index;

        up1 = findUpperPixels(img1);
        up1Length = index;

        inv1 = 255 - img1;
        thinning(inv1);

        vp1 = verticalProjection(inv1);

    }

    vector<cv::String> fn2;
    glob("preprocessed_cpp/*.jpg", fn2, false);
    size_t count2 = fn2.size();

    for (size_t j = 0; j < count2; j++)
    {
        img2 = imread(fn2[j], 0);
        score = 0;
        if (preprocessImage)
        {
            img2 = preProcess(img2);
        }


        if (lp ...
(more)
2015-06-17 23:01:52 -0600 asked a question How to use gabor filter to extract features in opencv using python?

I am trying to build a facial expression recognition algorithm. The face detection and cropping of face part is done. Would like to know further how can I extract features from image using the gabor filter in opencv using python.

2015-06-17 01:01:10 -0600 asked a question Can anyone give me automatic facial landmark detector code in opencv using python?

I want to do an expression recognition algorithm..I am going with the geometric based approach for this, that is the features extracted will be the fiducial points on eyebrow, nose, mouth,eyes etc...So I want a automatic facial landmark detector.

2015-06-16 05:06:32 -0600 commented question How to read latest image file from a folder in openCV using python?

ok..let me know how it can be done?

2015-06-16 04:49:59 -0600 asked a question How to read latest image file from a folder in openCV using python?

I want to read the latest image stored in a folder using the python opencv. How can I do this?

2015-06-16 01:12:17 -0600 commented question Face detection using Cascade Classifier in opencv pyhton

problem solved

2015-06-16 00:22:19 -0600 commented question Face detection using Cascade Classifier in opencv pyhton

yeah that was solved..but then faces are not detected...

2015-06-16 00:07:14 -0600 commented question Face detection using Cascade Classifier in opencv pyhton

you mean to say the 'haarcascade_frontalface_default.xml' file path?

2015-06-15 23:49:24 -0600 received badge  Editor (source)
2015-06-15 23:41:31 -0600 asked a question Face detection using Cascade Classifier in opencv pyhton

I am using the inbuilt cascade classifier for the face detection. This is how the code is (OpenCV Python Tutorials):

import numpy as np
import cv2

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')

img = cv2.imread('ammma.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, 1.3, 5)

for (x,y,w,h) in faces:
    cv2.Rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    roi_gray = gray[y:y+h, x:x+w]
    roi_color = img[y:y+h, x:x+w]
    eyes = eye_cascade.detectMultiScale(roi_gray)
    for(ex,ey,ew,eh) in eyes:
        cv2.Rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)

cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

But when I run the code I am getting the following error:

OpenCV Error: Assertion failed (!empty()) in cv::CascadeClassifier::detectMultiScale, file C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\objdetect\src\cascadedetect.cpp, line 1634 Traceback (most recent call last): File "C:/Users/DELL/Downloads/Amma/code/fd.py", line 10, in faces = face_cascade.detectMultiScale(img, 1.3, 5) cv2.error: C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\objdetect\src\cascadedetect.cpp:1634: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale

What is wrong with the code?