Ask Your Question

willoughby's profile - activity

2020-08-16 12:09:14 -0600 received badge  Student (source)
2020-08-16 12:08:12 -0600 received badge  Popular Question (source)
2016-05-25 08:54:36 -0600 commented question WHY ARE SPLIT MATS NOT CONTINOUS

image is continuous

2016-05-24 15:23:47 -0600 commented question WHY ARE SPLIT MATS NOT CONTINOUS

The image is 1138 x 912. I'm trying to run it on Mac OSX here is the image Test Image

2016-05-24 13:32:30 -0600 asked a question WHY ARE SPLIT MATS NOT CONTINOUS

so I split an into is seperate colors (using split on the matrix). When I then try to reshape one of the resulting matrix I get the following error:

OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in reshape, file /tmp/opencv3-20160429-9997-hdwo4d/opencv-3.1.0/modules/core/src/matrix.cpp, line 997

so then I quickly wrote the following code:

cv::Mat image = cv::imread(inputImageName,CV_LOAD_IMAGE_COLOR);
cv::Mat colorMats[3];
cv::split(image,colorMats);
for (int i=0;i < 3;++i)
{
    std::cout<<colorMats[i].isContinuous()<<std::endl;
}

and got the following result

1
1
0

why is the last one not continuous ?

2016-05-24 12:35:19 -0600 asked a question Take every Nth element of a matrix

I am trying to create a block average filter of an image.

In Matlab my code looks like:

ba=4; %block average block size
B = ones(ba)/ba^2;
out1 = conv2(double(rgb_img(:,:,1))/255,B,'valid');
out1 = out1(1:ba:end,1:ba:end);
out2 = conv2(double(rgb_img(:,:,2))/255,B,'valid');
out2 = out2(1:ba:end,1:ba:end);
out3 = conv2(double(rgb_img(:,:,3))/255,B,'valid');
out3 = out3(1:ba:end,1:ba:end);

I know how to do the first step using filter2D how do I do the second step (take every 4th element)

2016-05-24 09:09:23 -0600 commented question Filter for covariance
2016-05-23 09:59:03 -0600 asked a question Filter for covariance

Ok, so this may seem a little odd but bear with me.

I have an image, and I have a line (point slope form). What I need is a way to find the covariance above the line and the covariance below the line.

I have brute forced this by copying all of the pixels above/below the line into a new cv::Mat one by one (while keeping track of count and sum color as I do this), and then calculating the convariance manually.

While I am geting the results that I want this is incrediblly slow. Ideally I want to add GPU acceleration however because cv::GpuMat doesn't have direct access I cant exclude the unwanted pixels from either the count or the sum color.

I believe the key is to use some kind of filter however that concept is completly foreign and I am having trouble understanding what I need to do using the documentation.

Could someone please help me bring these cookies to a lower shelf.

Thanks

L.

2016-03-29 11:42:07 -0600 received badge  Editor (source)
2016-03-29 11:41:14 -0600 asked a question Calculate Covariance

I have a matrix (an image). And I want to calculate the covariance of the colors. However, there are sections of the matrix that are blank (-1,-1,-1) that I want to ignore in the covariance calculation. Currently, I am doing this process manually like so :

  1. iterate over every pixel: if not equal to (-1,-1,-1) subtract mean color (calculated during matrix generation), if equal to (-1,-1,-1) set to (0,0,0)

  2. Split Matrix into 3 color matrices

  3. Reshape each color matrices into column matrix

  4. Recombine column color matrices

  5. Multiply by transpose and divide by count - 1 (count does not include (-1,-1,-1) pixels)

I would like to add GPU (CUDA) support and use calcCovarMatrix() However I don't know if it is possible to get this function to perform this operation. Any help would be nice.

PS. Here is my Code

updateCovariance(cv::Mat matrix, cv::Mat covariance Vec3f averageColor, int count){
/*DEFINE VARIABLE*/
cv::Mat meanDifference(matrix.rows,matrix.cols,matrix.type());

std::vector<cv::Mat> colors(3);
std::vector<cv::Mat> columnColor(3, cv::Mat(matrix.rows*matrix.cols,1,matrix.type()));

cv::Mat colorMat(matrix.rows*matrix.cols,3,matrix.type());
cv::Mat colorMatTrans(3,matrix.rows*matrix.cols,matrix.type());

/*RUN CODE*/
for(int y = 0; y < meanDifference.rows; ++y)
{
    for (int x=0; x<meanDifference.cols; ++x)
    {
        if (matrix.at<cv::Vec3f>(y,x) != cv::Vec3f(-1,-1,-1))
        {
            meanDifference.at<cv::Vec3f>(y,x) = matrix.at<cv::Vec3f>(y,x)-averageColor;
        }
        else
        {
            meanDifference.at<cv::Vec3f>(y,x) = cv::Vec3f(0,0,0);
        }
    }
}
split(meanDifference,colors);

//Reshape Color Matrices into column arrays
for(int i=0;i < colors.size();++i)
{
    columnColor[i] = colors[i].reshape(1,1);
}

//Recombine color matrices and transpose
vconcat(columnColor,colorMat);

transpose(colorMat,colorMatTrans);

covariance = (colorMat * colorMatTrans)/(count-1);
/*CLEAN UP*/
/*RETURN*/
}
2016-03-29 11:16:03 -0600 received badge  Enthusiast
2016-03-29 11:16:03 -0600 received badge  Enthusiast
2016-03-16 16:01:22 -0600 commented question CommandLineParser only gets True

I did read the documentation. Are you referring to a particular part of the documentation

2016-03-16 13:38:26 -0600 asked a question CommandLineParser only gets True

So I am trying to use a CommandLineParser to parse arguments. I was having little luck so I tryed to create a simple case and see what was going on. Here is my code :

int main(int argc, const char* argv[])
{
   // Define and process cmdline arguments.
   CommandLineParser cmd(argc, argv,
       "{ i input            |           | Input video }"
       "{ ifd in_frame_dims  |           | Input frame dimensions }"
       "{ ifr in_frame_roi   |           | Input frame roi }"
       "{ ofd out_frame_dims |           | Output frame dimensions }"
       "{ o output           |           | Output video }"
       "{ s scale            | 4         | Scale factor }"
       "{ t temporal         | 4         | Radius of the temporal search area }"
       "{ h help             |           | Print help message }"
   );

   // Process cmd line help.
   if (cmd.get<bool>("help"))
   {
       cout << "Help" << endl;
       cmd.printMessage();
       return 0;
   }
   cout<<"string: "<<cmd.get<string>("input")<<endl;
   cout<<"bool: "<<cmd.get<bool>("input")<<endl;
   cout<<"int: "<<cmd.get<int>("input")<<endl;

   return 0;
}

now when I call this like so :

./ArgTest -i test.avi -ifd 320x240 -ifr 0x0+320x240 -ofd 640x480 -s 2 -t 2 -o testout.avi

I get :

string: true
bool: 1
OpenCV Error: Bad argument (can not convert: [true] to [int]) in from_str, file /Users/willoughby/Documents/packages/opencv-3.1.0/modules/core/src/command_line_parser.cpp, line 98
int: 0

It doesn't matter which key I used "cmd.get<string>("key") always returns true

what am I doing wrong

2016-03-15 15:10:27 -0600 asked a question VideoWriter undefined

I am writing some code to work with superres. In a cpp I include the following

"opencv2/core/core.hpp" "opencv2/videoio.hpp" "opencv2/highgui/highgui.hpp"

however when I go to build I get the following error:

"cv::VideoWriter::open(cv::String const&, int, double, cv::Size_<int>, bool)", referenced from: _main "cv::VideoWriter::VideoWriter()", referenced from: _main "cv::VideoWriter::~VideoWriter()", referenced from: _main "cv::VideoWriter::operator<<(cv::Mat const&)", referenced from: _main

what am I missing ?

Thanks Ahead of time

2016-03-14 15:08:27 -0600 asked a question Spliting GpuMat along a line

So I have and image and a line. I want to copy all of the pixel <vec3f> above the line into a GpuMat called sky and all the pixels below the line int a GpuMat called ground. I understand that I cannot iterate over a GpuMat the same way I can a normal mat. I am going to be seperating across every possible line one at a time so the fewer times that I transition between mat and GpuMat the better. Any advice?

2016-02-23 08:56:16 -0600 received badge  Scholar (source)
2016-02-23 08:55:59 -0600 received badge  Supporter (source)
2016-02-22 16:12:12 -0600 asked a question Subract one mat from another if a condition is met

I have 2 matrices of the same size. One of which has a "black area" where all the values are Scalar(0,0,0). I want to subtract the other matrix from this one but only in places where it isn't black (I want to leave the black alone). Id prefer not to iterate over the entire matrix if possible. I believe this is done using a mask but I am unclear how to set that up.

Thanks In Advance

2016-02-18 09:51:01 -0600 asked a question All points above a line

I have an image and a line bisecting that image (with a slope between -1.0 and 1.0). Is there an effective way to access all points above the line?