我掃描了由不同噴墨列印機(愛普生、惠普、佳能等)列印的檔案。每張照片都具有非常高的質量(例如 1.6GB),您可以放大并查看使用頻率調制的圖片的半色調。
我的任務是根據網格點、網格圖案、點的距離等進行特征提取。
相關的特征是這些點的大小(每臺列印機列印這些點的大小不同——必須計算平均值和標準偏差)。
稍后我將不得不用 ML 訓練一個模型,訓練后的模型應該將列印分類到特定的列印機(所以基本上這個列印屬于列印機 XYZ)。
但是現在我已經在特征工程和預處理方面苦苦掙扎,因為這實際上是我的第一個計算機視覺專案,而且我對 opencv 不太熟悉。
我有一個想法,我的計劃是使用影像的 opencv 進行二進制轉換,以通過 Sobel 或 Prewitt 過濾器或其他任何方式確定邊緣(邊緣檢測)。所以我想我必須先添加一些模糊,然后再進行邊緣檢測?
我不確定這是否是正確的方法,所以我在這里問,你怎么看?如果您能給我一些提示或步驟以獲得最佳方法或好的方法,我會很高興。

uj5u.com熱心網友回復:
這是 Python/OpenCV 中的一種方式。
使用 cv2.inRange() 設定顏色閾值。在這種情況下,我將在藍點上設定閾值。然后獲取所有外部輪廓以找到所有孤立區域。根據輪廓,計算等效圓直徑。然后計算平均值和標準偏差。
輸入:

import cv2
import numpy as np
import math
img = cv2.imread("color_dots.png")
# threshold on blue color
lower = (190,150,100)
upper = (255,255,170)
thresh = cv2.inRange(img, lower, upper)
# get external contours
contours = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = contours[0] if len(contours) == 2 else contours[1]
count = len(contours)
sum = 0
sum2 = 0
for cntr in contours:
# get area from contours and then diameters of equivalent circles
area = cv2.contourArea(cntr)
# area = pi*radius**2 = pi*(diameter/2)**2 = (pi/4)*diameter**2
# diameter = sqrt(4*area/pi) = 2*sqrt(area/pi)
diameter = 2 * math.sqrt(area/math.pi)
sum = sum diameter
sum2 = sum2 diameter * diameter
# compute average2 (mean)
average = sum/count
average2 = sum2/count
# compute standard deviation
variance = average2 - average*average
standard_deviation = math.sqrt(variance)
# print results
print("average:", average)
print("std_dev:", standard_deviation)
# save result
cv2.imwrite("color_dots_blue_threshold.png",thresh)
# display result
cv2.imshow("thresh", thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()
閾值影像:

結果:
average: 3.0747726858108635
std_dev: 0.541288251281962
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/340886.html
