# mainul's profile - activity

2014-07-21 14:26:39 -0500 asked a question Changing color space in opencv without changing color of the image

Hi, I am working on a project where I read an image load the data into Mat data type. The I do some operations on it. All my operations are done assuming the color space is RGB (BGR as opencv stores in that way). Everuything is working fine. I was doing experiment on converting the output image to YUV format. But when I transform the output image from BGR2YUV using the following command cvtColor(img,out,CV_RGB2YCrCb); I found that the resulting image color is changed completely.

How can I change the color space from RGB to YUV without changing the colors in the image? For example, my output RGB image is green. WHen I convert this to YUV format and show the resulting image I found it blue and NOT green. I want a way to convert so that the output also become green.

2014-07-07 14:42:01 -0500 asked a question solution to CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST error

Hi,

I am trying to run face detection on a 5 minute 720P video. I am using opencv API and opencl kernels to do my job. When I try to run the program, it runs fine for intial few number of frames. But after, some frames it gives me an error

OpenCV Error: Gpu API call (CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST) in openCLMemcpy2D, file /opencv-2.4.6.1/modules/ocl/src/initialization.cpp, line 466

Sometimes I get this error after processing 200 frames, sometimes I get this error after 2000 frames. Can anyone suggest me why I am facing this error and what could be a possible solution? I searched internet but did not find anythng.

Here is my psuodo code:

Main()
{
for (;;)
{
grab a frame;
detectface(frame);
}
}

detectface(frame)
{
tranfer frame to oclMatrix;

while some conditions are true:
while some conditions are true:
kernel1; //parameter: one oclmatrix for source, one for output, two temporary ocl matrix for calculation
kernel2;//parameter: one oclmatrix for source, one for output, one temporary ocl matrix for calculation
kernel3;//parameter: one oclmatrix for source, one for output, two temporary ocl matrix for calculation
kernel4;//parameter: one oclmatrix for source, one for output, one temporary ocl matrix for calculation
end;
kernel5; //this does the detection and gives a output. parameter: one oclmatrix for source, one for output, 4 temporary ocl matrix for cascade classifier.
end;

}

2014-06-03 11:41:38 -0500 asked a question How to get device list from context

Hi,

I am developing a project using opencv and opencl. Right now, the kernels and the buffer runs using the opencv specified functions. For some reasons, I want to use OpenCL's native function instead of opencv function with least number of changes. I have two files. In the main file I created the context and pass it to the function to the second file. In the second file I need to build and execute kernel. If I would use OpenCV's function I can use execute kernel with the context that has been passed to the second file. But as I am planning to use OpenCL's native one, I need to bild the kernel and for that I need device list. My question is, is there any way I can get the device list from opencv created context? or how can I get the device list without passing the info from the main file?

Here is the snippet of main file:

     vector<ocl::Info> oclinfo;
int devnums = ocl::getDevice(oclinfo);
if( devnums < 1 )
{
std::cout << "no device found\n";
return -1;
}
ocl::setBinpath("./");
cv::ocl::Context* clCxt = ocl::Context::getContext();

ScanKernel( Mat& img,string kernelsrc,string kernelName,cv::ocl::Context* clCxt)


here is the code snippet of the second file:


const char * source = kernelsrc.c_str(); size_t sourceSize[] = { strlen(source) };

cpProgram = clCreateProgramWithSource((cl_context)clCxt->oclContext(), 1, &source, sourceSize, &ciErr1);
if (ciErr1 != CL_SUCCESS) {
printf("Error in clCreateProgramWithSource, Line %u in file %s %d !!!\n\n", __LINE__, __FILE__,ciErr1);

}
else
{       printf("*** Got createprogramwithsource\n");

**ciErr1 =  clBuildProgram(cpProgram, NULL, NULL, NULL, NULL, NULL);**
if (ciErr1 != CL_SUCCESS) {
printf("Error in building, Line %u in file %s error NO: %d!!!\n\n", __LINE__, __FILE__,ciErr1);

}


I need help on getting the device list for clBuildProgram function.

2014-05-11 12:25:11 -0500 asked a question Weird behavior of ocl matrix in opencv

Hi,

I am faciong a qweird problem. I have two matrix, input and output. For each element i in a row r in the input matrix, it sums all element before i in that row and put the sum in i th column and r th row in output matrix. When I do this for small matrix, it gives me no problem. But for a big matrix (604x454), the output matrix contains GRARBAGE value in all output matrix rows except the first row.

"__kernel void "
"  v2_integral_cols_sum(__global uchar *src,\n"
"int rows,int cols,__global int *lm_sum, int pixels,int steps,int o_steps)\n"
"{\n"

"int gid=get_global_id(0);\n"
"if(gid>=pixels)"
"return;\n"
"else \n"
"{"
"int x = gid % steps;\n"
"int y = gid / steps;\n"
"int sum=0;\n"

"for (int i=0;i<=x;i++)"
"{\n"
"sum=sum+src[y * steps + i];\n"
"}\n"

"lm_sum[y*o_steps + x]=sum;\n"

"}"

"}\n"


interestingly if I use the printf statement after the output assignment statement as in this block,I get correct output matrix. I do not find any explanation of this weird behavior. Anyone can help me?

"lm_sum[y*o_steps + x]=sum;\n"
"if(gid==640)\n"
"{"

"printf(\"lm_sum [%d %d %d] %d  \",x,y,gid,lm_sum[y * o_steps+ x]);\n"

"}\n"

2014-04-24 11:02:06 -0500 asked a question data transfer between ocl matrix of type CV_32FC1 and CV_8UC1

I have created to ocl matrix of same size (rows and columns) bu different types. In my opencl code I am trying to transfer the data from CV_8UC1 matrix to CV_32FC1 matrix. I can see the values are correct when I used printf from kernel. But when I downloaded the output ocl matrix and printed the values in file I got wrong values. Here is my kernel:

"__kernel void " " v2_integral_cols_sum(__global uchar *src,\n" "int rows,int cols,__global int *lm_sum, int pixels,int steps,int o_steps)\n" "{\n"

                "int gid=get_global_id(0);\n"
"if(gid>=pixels)"
"return;\n"
"else \n"
"{"
"int x = gid % steps;\n"
"int y = gid / steps;\n"
"int sum=0;\n"

"for (int i=0;i<=x;i++)"
"{\n"

"sum=sum+src[y * steps + i];\n"
"}\n"

"lm_sum[y * o_steps + x]=sum;\n"

"}"

"}\n"




Here is the host code:

ocl::oclMat lm_sum_mem; lm_sum_mem.create(src.rows,src.cols, CV_32FC1); args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data )); args.push_back( make_pair( sizeof(cl_int) , (void *)&src.rows )); args.push_back( make_pair( sizeof(cl_int) , (void *)&src.cols )); args.push_back( make_pair( sizeof(cl_mem) , (void *)&lm_sum_mem.data)); args.push_back( make_pair( sizeof(cl_int) , (void *)&npixels)); args.push_back( make_pair( sizeof(cl_int) , (void *)&src.step )); args.push_back( make_pair( sizeof(cl_int) , (void *)&lm_sum_mem.step ));

            size_t gt[3] = {1728, 1, 1}, lt[3] = {32, 1, 1};

if(calTime)
{
//double dtKERNL1=get_wall_timelbp();
gettime_tocalc2[0]=get_wall_timelbp();
}

//ocl::openCLExecuteKernel(clCxt, &lbpobjectdetect, "v2_integral_cols", gt, lt, args, -1, -1,build_options);
ocl::openCLExecuteKernel(clCxt, &lbpobjectdetect, "v2_integral_cols_sum", gt, lt, args, -1, -1,build_options);


Here is the file printing: Mat t_sumhost; lm_sum_mem.download(t_sumhost); std::stringstream strFname3; printf("loop count %d",loopCount); strFname3 << "Integral_Cols"<<loopcount&lt;&lt;".txt"; const="" char*="" filenames="strFname3.str().c_str();" file="" *fp="fopen(filenames," "w");<="" p="">

            fprintf(fp,"Columnn %2d Rows: %d\n: ", t_sumhost.cols,t_sumhost.rows);
for (int i = 0; i < t_sumhost.rows; i++)
{
fprintf(fp,"\nrow %2d: ", i);
for (int j = 0; j < t_sumhost.cols; j++)
{
fprintf(fp," %5d ", t_sumhost.at<int>(i,j));
}
}
fclose(fp);
`
2014-03-21 11:34:42 -0500 commented question How the lbpcascade_frontalface.xml work?

@StevenPuttemans I tried to search for answers. And, I could not get two clear answers on how lbpcascade_frontalface.xml works let alone 100 answers. May be you understand the algorithm and usage of the xml file very well. For you, answering this question might be a time waste. But I do not understand the algorithm and how the cascade (nodes, leaves, ntrees, features etc) are used in the algorithm. For me, finding answers for this question is top most priority. If you can please help me.

2014-03-21 10:40:07 -0500 commented answer LBP based Face Detection

Can you please provide some link on LBP papers or documents that gives a better understanding of features and face detection?

2014-03-21 10:03:38 -0500 asked a question LBP algorithm of OpenCV

HI Everyone,

I am working on LBP based face detection on openCV. I wanted to understand the algorithm clearly but I could not find any clear documents on these algorithm or their implementation. I have some very specific questions. Here they are:

1. In lbpCascade_frontal_face.xml: what is maxCatCount, maxWeakCount, minHitRate, maxFalseAlarm, weightTrimRate, maxDepth, internalNodes, leafValues, tree etc? I know they are used in the algorithm. But I do not understand the meaning of each one of them. For example, why we take a particular feature and not the other for a particular stage? how we are deciding which feature/ node to choose?

2.What is feature values in the LBP_frontal_face_classifier.xml? I know they are a vector of 4 integers. But how should I use this features? I though stage 0 access to the first feature but access is not in this pattern. What is the access pattern to this features?

1. All the papers in literature give a high level overview only. Their descriptions mainly consist of LBP calculation from neighborhood pixels. But how this LBP values is used against those elements in the classifier?

2. How does intergral image help in calculating LBP value of a pixel? Please do not give reference/answer using HAAR features. I know how HAAR is used. I need to understand LBP.

I read some papers, articles. But none clearly describes how LBP based face detection works or the algorithm in details. If someone wants to develop a face detection program on his own,what are the steps he should follow- no document describes that.

If anyone can help me with the answers it would be a great help for me. -you can answer the questions or you can direct me to someone who knows the answers or you can give me some link of articles/documents/papers that would help me to understand this algorithm.

-Hassan

2013-10-30 09:53:13 -0500 asked a question OpenCV compilation error with OpenCL 2.4.6.1

Hi,

I compiled OpenCV 2.4.6.2 from git earlier with opencl enabled for arm architecture and everything worked fine. Then I changed in the initialization file and added some printf statements and tried recompiling the opencv. But could not compile and got a number of errors. Then I downloaded another opencv from sourgeforge (version 2.4.6.1) and tried to compile it. It compiled successfully. But when I tried to recompile it with OpenCL-after 87% of compilation I got this error:

## /opencv/modules/ocl/src/imgproc.cpp: In function 'void cv::ocl::copyMakeBorder(const cv::ocl::oclMat&, cv::ocl::oclMat&, int, int, int, int, int, const Scalar&)': /opencv/modules/ocl/src/imgproc.cpp:748:9: internal compiler error: output_operand: invalid expression as operand Please submit a full bug report, with preprocessed source if appropriate. See <file: usr="" share="" doc="" gcc-4.6="" readme.bugs=""> for instructions. Preprocessed source stored into /tmp/cconMG0K.out file, please attach this to your bugreport. make[2]: * [modules/ocl/CMakeFiles/opencv_ocl.dir/src/imgproc.cpp.o] Error 1 make[1]: [modules/ocl/CMakeFiles/opencv_ocl.dir/all] Error 2 make: ** [all] Error 2

I have not changed any file. It was a fresh copy of opencv. But I do not know what's wrong. However I tried to download a copy from git but the git version is so changed that I have to do a lot of things/changes in my code to cope with the changes made in git version.

Can anyone kindly show me a path why I am getting that error and how to solve that?

2013-10-30 09:45:29 -0500 commented answer Passsing size of a parameter to the kernel

I did it in different way. I changed the kernel string before execution. And inside kernel I used a macro for size.

2013-10-30 09:44:37 -0500 commented answer Opencv OpenCL Compilation error: x was not declared in this scope

I do not know how to mark it as solved. I dont see any icon for that.

2013-09-26 13:10:36 -0500 asked a question Printing from inside module/src/initialization.cpp file

Hi, I am running codes with a opencl kernel on an arm architecture. When I run the program, it stops while calling kernel and gets timeout. I would like to know which function related to kernel is getting the error. So I want to have some printf statements inside the initialization file. I added some lines and recompile opencv but while running the program nothing is printed from initialization file. can anyone help me how I can make initialization file to print something?

2013-09-26 13:06:34 -0500 commented answer Opencv OpenCL Compilation error: x was not declared in this scope

Thank you. I passed the location of opencl while compiling the codes.

2013-09-26 12:52:42 -0500 commented answer Best way to add new projects/files using Opencv and OCL

Thanks for your answer. I did it in another way. I will do that in your way too. On a different note I have one question. I am running codes on an arm architecture. It stops while calling kernel and got timeout. I would like to know which function is getting the error. So I want to have some printf statements inside the initialization file. I added some lines and recompile opencv but when running the program nothing printed from initialization file. Do you know how I can make initialization file print something?

2013-09-24 12:09:15 -0500 asked a question Best way to add new projects/files using Opencv and OCL

Hi,

I have written some custom codes for facedetection that uses Opencv's libraries and opencl function. I copied my files in the sample folders and tried to compile but I got several errors. Most of them occurs because it cannot link the OpenCV files and OPencl files. So, I manually put the full path of the files in the headers of my files as well as Opencv's files. For example, I got an error that cl_mem is not declared in the scope. To overcome this I had to put the full path of CL.h to all the dependent files. This process worked and the program compiled successfully.

But I think this is not a good approach to manually put the path of dependent files in the header. The samples provided by opencv can easily link all the necessary files. So, there must be way that will automatically link any new files with opencv and opencl's dependent files.

So, I need your suggestion regarding the best way of adding new projrcts/files so that they can automatically link all the OpenCL and OpenCV files.

2013-09-22 18:28:45 -0500 asked a question Opencv OpenCL Compilation error: x was not declared in this scope

Hi I created a program using OpenCV in windows with visual studio. My program has two cpp files. Both of them include many library files. The main function is in detect.cpp file and the other file is lbp.cpp. In windows the program runs just fine and can get every library files and header files. But when I tried to compile the program in Linux it did not compile and gave me error. The file cannot find opencl's function and data type. It gives me this error:

‘cl_command_queue’ was not declared in this scope ‘cl_mem’ was not declared in this scope ‘cl_int’ was not declared in this scope

There are many of them. Anyone has an idea how to solve them? I checked other sample files and used the same headers as they used. But my program just does not compile. Please help.

2013-09-19 15:55:55 -0500 commented question Getting error while compiling opencv sample program

oh I forgot to mention that. I am using Ubuntu 12.04. I followed these two pages to install: http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/

Then I tried to compile and run the sample codes. I tried to run the CPP ones also but got the same error.

2013-09-19 14:09:04 -0500 asked a question Getting error while compiling opencv sample program

Hi,

I have installed opencv following the steps mentioned in opencv wiki. Then I tried to compile and build the sample programs provided in the sample folder I got error. I tried to run my code but that did not work so I tried to run the sample code first and I got the following error:

rt: No such file or directory pthread: No such file or directory m: No such file or directory dl: No such file or directory

I removed those rt,pthread,m,dl from opencv.pc file. Then I tried to compile the sample codes again. Now I got many more errors. For example:

compiling bgfg_codebook.cpp bgfg_codebook.cpp: In function ‘int main(int, const char*)’: bgfg_codebook.cpp:108:39: error: ‘cvCaptureFromCAM’ was not declared in this scope bgfg_codebook.cpp:113:57: error: ‘cvCreateFileCapture’ was not declared in this scope bgfg_codebook.cpp:128:46: error: ‘cvQueryFrame’ was not declared in this scope bgfg_codebook.cpp:145:37: error: ‘cvNamedWindow’ was not declared in this scope bgfg_codebook.cpp:171:42: error: ‘cvShowImage’ was not declared in this scope bgfg_codebook.cpp:177:25: error: ‘cvWaitKey’ was not declared in this scope bgfg_codebook.cpp:235:32: error: ‘cvReleaseCapture’ was not declared in this scope bgfg_codebook.cpp:236:28: error: ‘cvDestroyWindow’ was not declared in this scope compiling blobtrack_sample.cpp blobtrack_sample.cpp: In function ‘int RunBlobTrackingAuto(CvCapture, CvBlobTrackerAuto, char, char*)’: blobtrack_sample.cpp:140:64: error: ‘cvWaitKey’ was not declared in this scope blobtrack_sample.cpp:152:33: error: ‘cvQueryFrame’ was not declared in this scope blobtrack_sample.cpp:175:50: error: ‘CV_FOURCC’ was not declared in this scope blobtrack_sample.cpp:177:27: error: ‘cvCreateVideoWriter’ was not declared in this scope.

I installed and reinstalled opencv three times. But still no luck. I tried to run the sample codes from this location: Opencv/samples/c/

I do not know what to do now. Can anyone help me with some idea?

2013-09-18 13:40:33 -0500 commented question Compiling prgram with OpenCV in Linux

The original haar.cpp file has that header file and as my lbp.cpp also quite similar to haar I kept it. However, removing the header line or placing lbp.cpp file in teh same location as haar.cpp gives me some different error. It says that some functions are not declared in the scope. My question is if you have a main file and a function file both of which use OpenCV and OpenCL, how will you compile that code? Any help will be appreciated.

2013-09-18 12:24:51 -0500 asked a question Compiling prgram with OpenCV in Linux

Hi I created a program using OpenCV in windows with visual studio. My program has two cpp files. Both of them include many library files. The main function is in detect.cpp file and the other file is lbp.cpp. In windows the program runs just fine and can get every library files and header files. But when I tried to compile the program in Linux it did not compile and gave me error. For simplicity I put the both the cpp files in the same directory and placed this directory in opencv samples folder. But when I tried to compile I got this error:

fatal error: precomp.hpp: No such file or directory

But this file is there in /modules/core/src folder. I am not sure why it cannot find the file. How can I pass the file location while compiling? can anyone suggest me some tutorial how I can compile my code? I searched some articles but they are not helping.

Thanks

2013-09-16 18:15:01 -0500 asked a question Passsing size of a parameter to the kernel

Hi,

I have a kernel that has a local variable __local int* sbuff as parameter. I want to set its size dynamically. In normal opencl we can do that using setkernelArg function. But in OpenCV they provides a wrapper to execute kernel and passing parameter. For example, we use openCLExecuteKernel to execute kernel and args.push_back to pass parameter.

My question is how I can pass the size of the local variable to the kernel using OpenCV's functions?

2013-09-05 13:33:20 -0500 commented answer Problems with the opencv document

ok, I will. I thought this topic has answer that contains area that resembles mine, so I asked here thinking that I might get an answer quickly. I will ask a new question.

2013-09-05 13:05:47 -0500 commented answer Problems with the opencv document

What is CV_EXPORTS? I see this macros in so many places. But could not really understand what it is. There is no information about it also. I also want to know what NCV_STATUS and NCV_EXPORTS is? what is the difference between CV and NCV? can anyone enlighten me?

2013-09-05 13:05:17 -0500 answered a question Problems with the opencv document

What is CV_EXPORTS? I see this macros in so many places. But could not really understand what it is. There is no information about it also. I also want to know what NCV_STATUS and NCV_EXPORTS is? what is the difference between CV and NCV? can anyone enlighten me?

2013-09-05 10:20:56 -0500 asked a question What is nppiStIntegralGetSize_8u32u , NCV, NCV_Exports

Hi, I have starting working on OpenCV recently. While working on it, I stumbled upon some functions about which I know nothing about. I was checking the LBP facedetect codes for CUDA. There I found a function nppiStIntegralGetSize_8u32u. I found no implementation of this file or any substantial information on it. Can anyone tell me what this is? what is NCV or NCV Exports. Please let me know something.