moving from c++ opencv to c# emgu cv? -
i'm new on c# want translate code c++ c#. program consist on determinig if image white or not that's why try value of pixel , comparing 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; } }
i proced still don't working
int image_blanche(string str,int prctge) { image<bgr, byte> img = new image<bgr, byte>(str); int compt = 0; int i; int j; ( = 0; < img.width; i++) { ( 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; }
any please.
have tried opening image bitmap?
bitmap img = new bitmap(file path);
then you have method
color c = img.getpixel(x,y)
well if image pure white, every pixel must equal 255 (for 8 bit greyscale image), or [255 255 255] (for 8 bit color image). loop through rows , columns of image , count values @ each pixel. once have total, compare total of how many there in white image of same size i.e. width*height*255 greyscale image, or width*height*255*3 color image. percentage of whiteness in test image dividing count total white image. i.e. test_img_total / width*height*255*3
Comments
Post a Comment