直接上代码吧: import cv2 import numpy as np from PIL import Image area = def getWhitePixel(img): global area image=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(image,(,),) ret3,th3 = cv2.threshold(blur,,,cv2.THRESH_BINARY+cv2.THRESH_OTSU)…
int histo[256] = { 0 };//直方图统计每个像素值的数目 int width = img.cols, height = img.rows; int num_of_pixels = width*height; //统计每个像素值的数目 for (int y = 0; y < height; ++y) { auto *data = new uchar[width * height * 3]; for (int x = 0; x < width; ++x) { histo[dat…
这是个简单的算法,是全局二值算法的一种,算法执行速度快. 算法过程简单描述如下: 对于每一个像素,做如下处理 1.计算当前像素水平和垂直方向的梯度. (two gradients are calculated |I(x + 1, y) - I(x - 1, y)| and |I(x, y + 1) - I(x, y - 1)|); 2.取两个梯度的最大值作为权重.(weight is calculated as maximum of two gradients); 3.更新权重的和…