title: combined Scharr derivatives in opencv
body: <p>I have few questions regarding Scharr derivatives and its OpenCV implementation.</p>
  
  <p>I am interested in second order image derivatives with (3X3) kernels.
  I started with Sobel second derivative, which failed to find some thin lines in the images. After reading the Sobel and Charr comparison in the bottom of <a href="http://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html?highlight=sobel#void%20Scharr(InputArray%20src,%20OutputArray%20dst,%20int%20ddepth,%20int%20dx,%20int%20dy,%20double%20scale,%20double%20delta,%20int%20borderType)" rel="nofollow noreferrer">this page</a>, I decided to try Scharr instead by changing this line:</p>
  
  <p><code>Sobel(gray, grad, ddepth, 2, 2, 3, scale, delta, BORDER_DEFAULT);</code></p>
  
  <p>to this line:</p>
  
  <p><code>Scharr(img, gray, ddepth, 2, 2, scale, delta, BORDER_DEFAULT );</code></p>
  
  <p>My problem is that it seems like cv::Scharr allows performing an only first order of one partial derivative at a time, So I get the following error:</p>
  
  <p><strong><em>error: (-215) dx >= 0 &amp;&amp; dy >= 0 &amp;&amp; dx+dy == 1 in function getScharrKernels</em></strong></p>
  
  <p>(see assertion line <a href="https://github.com/opencv/opencv/blob/master/modules/imgproc/src/deriv.cpp#L66" rel="nofollow noreferrer">here</a>)</p>
  
  <p>Following this restriction, I have a <strong>few questions</strong> regarding Scharr derivatives:</p>
  
  <ol>
  <li>Is it considered bad-practice to use high order Scharr derivatives? Why did OpenCV choose to assert  <code>dx+dy == 1</code>?</li>
  <li><p>If I am to call Scharr twice for each axis, What is the correct way to combine the results?
  I am currently using:</p>
  
  <p><code>addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad );</code></p>
  
  <p>but I am not sure that this how the Sobel function combines the two axis and in what order it should be done for all 4 derivatives.</p></li>
  <li><p>If I am to compute the (dx=2,dy=2) derivative by using 4 different kernels, I would like to reduce processing time by unifying all 4 kernels into 1 before applying it on the image (I assume that this is what cv::Sobel does). Is there a reasonable way to create such combined Shcarr kernel and convolve it with my image?</p></li>
  </ol>
  
  <p>Thanks!</p>