[英]Emgu.CV.Util.CvException: 'OpenCV: cv::XMLParser::parse' Error C#
[英]moving from c++ opencv to c# emgu cv?
我是C#的新手,我想將此代碼從c ++轉換為c#。 該程序取決於圖像是否為白色,這就是為什么我嘗試獲取所有像素的值並將其與0進行比較的原因。
int image_blanche(char * str, double prctage){
Mat img=imread(str);
int compt=0;
for(int i=0;i<img.rows;i++){
for(int j=0;j<img.cols;j++){
if (img.at<uchar>(i,j)==0){
compt=compt+1;
}
}
}
if (compt< img.rows*img.cols*prctage)
{
return 1;
}
else if (compt> img.rows*img.cols*prctage){
return 0;
}
}
我這樣處理,但仍然無法正常工作
int Image_blanche(String str,int prctge)
{
Image<Bgr, Byte> img = new Image<Bgr, Byte>(str);
int compt = 0;
int i;
int j;
for ( i = 0; i < img.Width; i++)
{
for ( j = 0; j < img.Height; j++)
{
Bgr color = img[i, j];
if ((Math.Abs(color.Green - 0) < 0) &&(Math.Abs(color.Blue - 0) < 0)&&(Math.Abs(color.Red - 0) < 0))
{
compt = compt + 1;
}
}
}
return compt <= img.Width*img.Height*prctge ? 1 : 0;
}
請幫忙。
您是否嘗試過將圖像作為位圖打開?
Bitmap img = new Bitmap(file path);
那你有方法
Color c = img.GetPixel(x,y)
好吧,如果圖像是純白色的,則每個像素必須等於255(對於8位灰度圖像)或[255 255 255](對於8位彩色圖像)。 因此,您可以遍歷圖像的行和列並計算每個像素處的值。 一旦有了總數,就將其與相同大小的白色圖像的總數進行比較,例如,對於灰度圖像,寬度*高度* 255,對於彩色圖像,寬度*高度* 255 * 3。 通過將計數除以白色圖像的總數,還可以得到測試圖像中白色的百分比。 即test_img_total /寬度*高度* 255 * 3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.