Ask Your Question

awu's profile - activity

2020-07-16 22:56:47 -0600 received badge  Popular Question (source)
2013-09-06 17:25:06 -0600 asked a question CMake CUDA master errors

I'm on the master branch and I'm failing to compile with CUDA. It builds fine without CUDA on my laptop.

The first errors (with multiple line numbers = x) are: (x): error: too few arguments in invocation of macro "CV_StaticAssert" in files opencv/modules/core/include/opencv2/core/matx.hpp opencv/modules/core/include/opencv2/core/operations.hpp opencv/modules/cudev/include/opencv2/cudev/grid/copy.hpp opencv/modules/cudev/include/opencv2/cudev/grid/transform.hpp

I can fix that by just removing the definition for CV_StaticAssert in base.hpp. However, the next error is No rule to make target lib/libopencv_cudev.so.2.9.0 needed by lib/libopencv_core.so.2.9.0

Should this go in the bugs tracker?

2013-08-29 18:55:58 -0600 commented question Alpha-Dependent Template Matching

@LadyZayin Apologize for the late response, I didn't notice any notification on the comment. The crossCorr function I used is the same one in OpenCV, but glad that you solved the problem.

2013-07-26 13:53:22 -0600 received badge  Student (source)
2013-07-10 22:54:36 -0600 received badge  Editor (source)
2013-07-10 22:53:33 -0600 asked a question Alpha-Dependent Template Matching

I have a couple of pics that are either 8UC3 or 8UC4 and I would like to template match them almost exactly. I have done this in my code, and I would like to learn if there are better methods to optimize and simplify the code? In also know that it is currently done with block methods and fft, and also I have read about phase based matching. (CUDA's next, but this will do for now). I think I have moved everything out of the loop that is possible. Breaking during GDB sessions usually end up on the multiply or the merge in the loop. I also haven't guarded against all possible values of different types and perhaps there are better ways to guard against different types? (I think my code will fail for graychannel with alpha). Last, what is the best way to guard against matching against a black patch since everything will be 0.

I have also referred to these codes, but I developed my own:

Thanks

alpha-dependent template matching

opencv template matching and transparency

Mat templ = _templ.getMat();
Mat img = _img.getMat();
const double UCHARMAX = 255;
const double UCHARMAXINV = 1./UCHARMAX;
Mat templRed(templ.size(), CV_8UC1);
Mat templGreen(templ.size(), CV_8UC1);
Mat templBlue(templ.size(), CV_8UC1);
Mat templAlpha(templ.size(), CV_8UC1);

Mat imgRed(img.size(), CV_8UC1);
Mat imgGreen(img.size(), CV_8UC1);
Mat imgBlue(img.size(), CV_8UC1);
Mat imgAlpha(img.size(), CV_8UC1);
if(templ.depth() == CV_8U && img.depth() == CV_8U && 
  (img.type() == CV_8UC3 || img.type() == CV_8UC4) &&
  (templ.type() == CV_8UC3 || templ.type() == CV_8UC4)){
  if(templ.type() == CV_8UC3){
    templAlpha = Scalar(UCHARMAX);
    cvSplit(&templ, &templRed, &templGreen, &templBlue, NULL);
  }
  else if(templ.type() == CV_8UC4){
    cvSplit(&templ, &templBlue, &templGreen, &templRed, &templAlpha);
  }
  if(img.type() == CV_8UC3){
    imgAlpha = Scalar(UCHARMAX);
    cvSplit(&img, &imgRed, &imgGreen, &imgBlue, NULL);
  }
  else if(templ.type() == CV_8UC4){
    cvSplit(&img, &imgBlue, &imgGreen, &imgRed, &imgAlpha);
  }
  Size corrSize(img.cols - templ.cols + 1, img.rows - templ.rows + 1);
  _result.create(corrSize, CV_32F);
  Mat result = _result.getMat();

  Mat tempRed=templRed.clone();
  Mat tempBlue=templBlue.clone();
  Mat tempGreen=templGreen.clone();

  multiply(tempRed, templAlpha, tempRed, UCHARMAXINV);
  multiply(tempGreen, templAlpha, tempGreen, UCHARMAXINV);
  multiply(tempBlue, templAlpha, tempBlue, UCHARMAXINV);

  multiply(imgRed, imgAlpha, imgRed, UCHARMAXINV);
  multiply(imgGreen, imgAlpha, imgGreen, UCHARMAXINV);
  multiply(imgBlue, imgAlpha, imgBlue, UCHARMAXINV);

  Mat temp(templ.size(), CV_8UC3);
  cvMerge(&tempBlue, &tempGreen, &tempRed, NULL, &temp);
  const double tempsum2 = norm(temp);

  Mat ROI(templ.size(), CV_8UC3);

  for(int i=0; i<img.rows-templ.rows; i++){
    for(int j=0; j<img.cols-templ.cols; j++){

      const Rect rect = Rect(j, i, templ.cols, templ.rows);
      Mat ROItempRed(imgRed, rect);
      Mat ROItempGreen(imgGreen, rect);
      Mat ROItempBlue(imgBlue, rect);

      Mat ROIRed = ROItempRed.clone();
      Mat ROIBlue = ROItempBlue.clone();
      Mat ROIGreen = ROItempGreen.clone();

      multiply(ROIRed, templAlpha, ROIRed, UCHARMAXINV);
      multiply(ROIGreen, templAlpha, ROIGreen, UCHARMAXINV);
      multiply(ROIBlue, templAlpha, ROIBlue, UCHARMAXINV);

      cvMerge(&ROIBlue, &ROIGreen, &ROIRed, NULL, &ROI);
      Mat corr(result, Rect(j, i, 1, 1));
      crossCorr( ROI, temp, corr, corr.size(), corr.type(), Point(0,0), 0, 0);
      const double normalization = norm(ROI)*tempsum2;
      if(normalization != 0)
        corr /= normalization;
      else
        corr = 0.; //How should black be matched?
    }
  }
}
//...  else ...
(more)