我有关于sobel操作的代码
Image<Gray, double> test_x= new Image<Gray, double>(img_gray.Size);
Image<Gray, double> test_y = new Image<Gray, double>(img_gray.Size);
Image<Gray, byte> final = new Image<Gray, byte>(img_gray.Size);
CvInvoke.Sobel(img_gray, test_x, DepthType.Cv64F,1,0);
CvInvoke.Sobel(img_gray, test_y, DepthType.Cv64F, 0, 1);
for (int x = 0; x < img_gray.Cols; x++)
{
for (int y = 0; y < img_gray.Rows; y++)
{
double mag = Math.Pow(test_x[y, x].Intensity, 2) + Math.Pow(test_y[y, x].Intensity, 2);
mag = Math.Sqrt(mag);
if (mag > 125)
{
final[y, x] = new Gray(255);
}
else
{
final[y, x] = new Gray(0);
}
}
}
imageBox2.Image = final;
该代码需要一些时间才能显示结果
opencv中是否有任何函数可以计算所有像素的大小而不访问所有像素
通过for循环
谢谢 :)
最佳答案
EmguCv具有此功能。我要多快决定
Image<Gray, double> test_x= new Image<Gray, double>(img_gray.Size);
Image<Gray, double> test_y = new Image<Gray, double>(img_gray.Size);
CudaImage<Gray, double> final = new CudaImage<Gray, double>(img_gray.Size);
CvInvoke.Sobel(img_gray, test_x, DepthType.Cv64F,1,0);
CvInvoke.Sobel(img_gray, test_y, DepthType.Cv64F, 0, 1);
CudaImage<Gray, double> xCuda = new CudaImage<Gray, double>(test_x);
CudaImage<Gray, double> yCuda = new CudaImage<Gray, double>(test_y);
CudaInvoke.Magnitude(xCuda, yCuda, final);