EmguCV C++ 转换 C# EmguCV
Posted
技术标签:
【中文标题】EmguCV C++ 转换 C# EmguCV【英文标题】:EmguCV C++ to convert C# EmguCV 【发布时间】:2014-09-09 23:17:09 【问题描述】:我正在尝试使用 EmguCV 在通道 H 中进行像素计数,大多数在 C ++ 中都有此代码,并且希望将 EmguCV c ++ 的部分转换为 C#,尤其是部分 uchartone = comp [ 0] .at (i, j);这让我很头疼,如果你能帮助我,非常感谢?
这是代码:
ProcessadorImagem::calculaHistograma(cv::Mat imagem, DadosImagem* dadosImagem)
cv::Mat hls;
cv::cvtColor(imagem, hls, CV_RGB2HLS_FULL);
cv::Mat* comp = new cv::Mat[3];
cv::split(hls, comp);
for (int i = 0; i < imagem.rows; i++)
for (int j = 0; j < imagem.cols; j++)
uchar tom = comp[0].at<uchar>(i, j);
for (int k = 0; k < dadosImagem->getHistograma().size(); k++)
uchar min = dadosImagem->getHistograma()[k]->getLimiteInicial();
uchar max = dadosImagem->getHistograma()[k]->getLimiteFinal();
if (tom >= min && tom <= max)
int contagem = dadosImagem->getHistograma()[k]->getContagemPixels();
dadosImagem->getHistograma()[k]->setContagemPixels(contagem + 1);
break;
【问题讨论】:
这行“uchar tom = comp[0].atpublic class ColorDetails
public Hsv hueLowerLimit get; set;
public Hsv hueUpperLimit get; set;
hueLowerLimit = new Hsv(hueLow, satLow, valLow);
hueUpperLimit = new Hsv(hueHigh, satHigh, valHigh);
====================
ColorDetails element = // add hue upperlimit and lower limit here
Image<Gray, byte> filteredImage = null;
//function to filter out a specified hue range
if (element.hueLowerLimit.Hue > element.hueUpperLimit.Hue)
filteredImage = hsvImage.InRange(element.hueLowerLimit, new Hsv(180, element.hueUpperLimit.Satuation, element.hueUpperLimit.Value))
.Add(hsvImage.InRange(new Hsv(0, element.hueLowerLimit.Satuation, element.hueLowerLimit.Value), element.hueUpperLimit));
else
filteredImage = hsvImage.InRange(element.hueLowerLimit, element.hueUpperLimit);
/*
//for debugging
Image<Bgr, Byte> masked = new Image<Bgr, byte>(image.Size);
image.Copy(masked, filteredImage);
Console.WriteLine("Color Count : " + filteredImage.CountNonzero()[0]);
CvInvoke.Imshow("out", masked);
CvInvoke.WaitKey(0);
*/
//this is the pixel count of a particular hue range
filteredImage.CountNonzero()[0]
【讨论】:
以上是关于EmguCV C++ 转换 C# EmguCV的主要内容,如果未能解决你的问题,请参考以下文章
如何在 EmguCV 中将图像转换为矩阵,然后将矩阵转换为位图?
OpenCv,EmguCv及.net之间的互动(The Interaction of OpenCv, EmguCv AND .net)