本博客講述的是獲取一張圖片首先對圖像進行處理,比如畸形矯正,圖像濾波等操作。
1.histeq()自適應直方圖均衡
# 自適應直方圖均衡例子
#
# 此示例展示了如何使用自適應直方圖均衡來改善圖像中的對比度。
#自適應直方圖均衡將圖像分割成區域,然后均衡這些區域中的直方圖,
#以改善圖像對比度與全局直方圖均衡化。
#此外,您可以指定剪輯限制以防止對比度變得狂野。histeq(adaptive=True, clip_limit=50)
# clip_limit <0為您提供正常的自適應直方圖均衡,這可能會導致大量的對比噪音...
# clip_limit=1 什么都不做。為獲得最佳效果,請略高于1,如下所示。
# 越高,越接近標準自適應直方圖均衡,并產生巨大的對比度波動。
如果沒有參數輸入那么久默認直方圖均衡,目增大對比度。
亮的地方更亮,暗的地方更暗
2.模糊濾波
sensor.set_framesize(sensor.QQVGA) img = sensor.snapshot() # 拍一張照片,返回圖像 # 在圖像的每個像素上運行核。
img.gaussian(1)
結論:通過對比不同的核數發現核數越大圖像越模糊,隨著核數的增大幀率也降低
3.核濾波
這個參數還沒搞懂,以后需要在研究,先速成在說
import sensor, image, timesensor.reset() # 初始化sensorsensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
#設置圖像色彩格式,有RGB565色彩圖和GRAYSCALE灰度圖兩種sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
#設置圖像像素大小sensor.skip_frames(time = 2000) # 讓新的設置生效
clock = time.clock() # 跟蹤FPS幀率kernel_size = 1 # 3x3==1, 5x5==2, 7x7==3, etc.kernel = [-2, -1, 0, \-1, 1, 1, \0, 1, 2]while(True):clock.tick() # 追蹤兩個snapshots()之間經過的毫秒數.img = sensor.snapshot() # 拍一張照片,返回圖像# Run the kernel on every pixel of the image.# 在圖像的每個像素上運行核img.morph(kernel_size, kernel)print(clock.fps()) # 注意: 當連接電腦后,OpenMV會變成一半的速度。當不連接電腦,幀率會增加。
上述代碼核濾波的效果
4.卡通化濾波-在我這個上無法使用
# seed_threshold控制著色區域的最大區域增長。 將其放大會合并更多像素。# floating_threshold控制增長區域時的最大像素到像素的差異。設置高的值將快速組合圖像中的所有像素。你應該使其小一些。# cartoon() 將增長同時兩個限制都滿足的區域...img = sensor.snapshot().cartoon(seed_threshold=0.05, floating_thresholds=0.05)
5.彩圖雙邊濾波
import sensor, image, timesensor.reset() # 初始化sensorsensor.set_pixformat(sensor.RGB565) # or sensor.RGB565
#設置圖像色彩格式,有RGB565色彩圖和GRAYSCALE灰度圖兩種sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
#設置圖像像素大小sensor.skip_frames(time = 2000) # 讓新的設置生效
clock = time.clock() # 跟蹤FPS幀率while(True):clock.tick() # 追蹤兩個snapshots()之間經過的毫秒數.img = sensor.snapshot() # 拍一張照片,返回圖像# color_sigma controls how close color wise pixels have to be to each other to be# color_sigma控制彩色明智像素之間必須有多近的距離才能模糊。# blured togheter. A smaller value means they have to be closer.# 更小的值意味著它們必須更接近。# A larger value is less strict.# 較大的值不那么嚴格。# space_sigma controls how close space wise pixels have to be to each other to be# space_sigma控制空間智慧像素彼此之間必須有多近才能模糊# blured togheter. A smaller value means they have to be closer.# 更小的值意味著它們必須更接近。# A larger value is less strict.# 較大的值不那么嚴格。# Run the kernel on every pixel of the image.# 在圖像的每個像素上運行核img.bilateral(3, color_sigma=0.1, space_sigma=1)# Note that the bilateral filter can introduce image defects if you set# color_sigma/space_sigma to aggresively. Increase the sigma values until# the defects go away if you see them.# 請注意,如果將color_sigma/space_sigma設置為聚合,雙邊過濾器可能會引入圖像缺陷。# 如果你看到缺陷,增加sigma值直到