Ask Your Question

maystroh's profile - activity

2020-04-21 12:58:48 -0600 received badge  Notable Question (source)
2018-09-08 03:46:56 -0600 received badge  Popular Question (source)
2016-12-16 03:29:19 -0600 received badge  Famous Question (source)
2016-12-16 03:29:19 -0600 received badge  Popular Question (source)
2016-12-16 03:29:19 -0600 received badge  Notable Question (source)
2016-01-12 08:14:31 -0600 received badge  Student (source)
2015-03-23 11:03:22 -0600 asked a question background substraction of an image

Actually, I'm trying to substract the background from this image. Apparantly, I just want to substract the green background and here is the code I'm using:

Mat img_object = imread(patternImageName);
Mat imageInHSV;
cvtColor(img_object, imageInHSV, CV_BGR2HSV);

Mat chan[3],imgThreshed, processed;
split( imageInHSV, chan );
Mat H = chan[0];
// compute statistics for Hue value
cv::Scalar mean, stddev;
cv::meanStdDev(H, mean, stddev);

// ensure we get 95% of all valid Hue samples (statistics 3*sigma rule)
float minHue = 80;
float maxHue = 95;
cout << "MinValue :" << mean[0] << " MaxHue:" << stddev[0] << endl;
cout << H << endl;
// STEP 2: detection phase
cv::inRange(H, cv::Scalar(minHue), cv::Scalar(maxHue), imgThreshed);
imshow("thresholded", imgThreshed);

I checked the values of the channel H to decide the minHue and maxHue so I choosed the interval of the most frequent values in the matrix which will definitely be the green one. But, I got this result which is obsiously not what I'm looking for because there is missing stuff in it. Any idea how to improve it? how to get better substract the background from this kind of images?

2015-03-10 06:49:56 -0600 asked a question kernel size of laplacian filter

In the documentation, they said "When ksize == 1 , the Laplacian is computed by filtering the image with the following 3 \times 3 aperture: image description"

What will be the filter when the kernel size is 3,5,7? Any idea about it?

Thanks.

2015-03-10 05:43:09 -0600 commented answer Convert from CV_32FC1 to binary

Yep, right. I just figured out.

2015-03-10 05:11:46 -0600 asked a question Convert from CV_32FC1 to binary

I have an image of type CV_32FC1 and I need to convert it binary without passing by the conversion to CV_8U since it seems to me that I'm loosing data by passing to it before going to binary.

result = Mat(res.size(),CV_32FC1); 
for (int i = 0; i < res.rows ; i ++)
        for (int j = 0; j < res.cols; j++)
        {
            result.at<float>(i,j) = (fabs(res.at<float>(i,j)) / 8);
        }
result.convertTo(result, CV_8U);
threshold(result, imageBinary, 30, 255, CV_THRESH_BINARY);

Any idea how can I achieve it?

2015-03-06 03:55:06 -0600 received badge  Enthusiast
2015-01-19 03:37:52 -0600 received badge  Supporter (source)
2015-01-19 03:37:49 -0600 commented answer ddepth parameter of the Laplacian filter

Ok cool, so convertScaleAbs( res, result); converts each channel of the image to 8bit right? if not, how can I display the image result of the laplacian?

2015-01-14 10:42:51 -0600 asked a question ddepth parameter of the Laplacian filter

Here how I used to implement the Laplacian filter over my images:

 int scale = 1;
 int delta = 0;
 int ddepth = CV_16S;
 int kernel_size = 3;
 Mat res,imgGrayScale, imgGrayScaleGaussianBlurred;
 cv::cvtColor(sourceImage, imgGrayScale, CV_RGB2GRAY);
 imwrite("Im3downsampledimgGrayScale.png",imgGrayScale);
 GaussianBlur( imgGrayScale, imgGrayScaleGaussianBlurred, Size(3,3), 0, 0, BORDER_DEFAULT );
 imwrite("Im3downsampledimgBlurred.png",imgGrayScaleGaussianBlurred);
 //Laplace
 Laplacian( imgGrayScale, res, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );
 convertScaleAbs( res, result);

Can someone clarify what it does the "ddepth" parameter? Why it states in the documentation that should be CV_16S to avoid overflow? What does it mean this?

ddepth: Depth of the destination image. Since our input is CV_8U we define ddepth = CV_16S to avoid overflow
2015-01-13 04:45:19 -0600 commented answer copy even rows/cols to another Mat

Thanks, that's it

2015-01-13 04:45:05 -0600 received badge  Scholar (source)
2015-01-13 04:23:44 -0600 commented answer copy even rows/cols to another Mat

see EDITED @berak

2015-01-13 04:11:45 -0600 commented answer copy even rows/cols to another Mat

This works if A has only one channel but what if I have a Mat of 3 channels? I'm sorry for this kind of question but I'm still newbie in openCV and don't know exactly how manipulate the variables

2015-01-12 10:01:50 -0600 received badge  Editor (source)
2015-01-12 09:46:40 -0600 asked a question copy even rows/cols to another Mat

I would like to get the even rows/cols of a mat of 3 channels, something like this:

A = 1 0 1 0 1 0
    1 0 1 0 1 0
    1 0 1 0 1 0

result = 1 1 1
         1 1 1

How to can I do this using openCV?

Thanks in advance.

EDITED:

Here is the code I could integrate:

 Mat img_object = imread(patternImageName);
 Mat B;
 for (int i = 0; i < img_object.cols; i += 2)
 {
      B.push_back(img_object.col(i));
 }
 // now we got 1 large 1d flat (column) array with all the collected elements,
 // let's make a 3x3 Mat of it again:
 B = B.reshape(-1,3);// 1 elem per channel, 3 rows.
 B = B.t();          // transpose it
 Mat B2;
 for (int i = 0; i < B.rows; i += 2)
 {
      B2.push_back(B.row(i));
 }
 imwrite("as.png",B2);

But it throws the following expection:

OpenCV Error: Assertion failed (src.dims <= 2 && esz <= (size_t)32) in transpose, file /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/matrix.cpp, line 2007
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/matrix.cpp:2007: error: (-215) src.dims <= 2 && esz <= (size_t)32 in function transpose

Am I missing something?