0
A
回答
1
您可以嘗試轉換爲HSV顏色空間和顏色閾值。但是,您可能無法將閾值作爲變量移除,因爲每個圖像的光照都有輕微的變化。從經驗中我可以告訴你,有時候你可以慷慨地擴展門檻,以適應大部分你想要的東西。但更通用的解決方案將需要更復雜的算法。
來自OpenCV的文檔:
11 # Convert BGR to HSV
12 hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
13
14 # define range of blue color in HSV
15 lower_blue = np.array([110,50,50])
16 upper_blue = np.array([130,255,255])
17
18 # Threshold the HSV image to get only blue colors
19 mask = cv2.inRange(hsv, lower_blue, upper_blue)
對於你那裏,你將不得不調整過程中的參數暗黃。
1
使用霍夫圓變換來查找分隔眼睛和灰色區域的圓。
其基本思想是運行Hough circle transfor,然後找到圈子內部與外部之間值最大的圓圈。
代碼:
import cv2
import numpy as np
# Read image
Irgb = cv2.imread('eye.jpg')
# Take the first channel (No specifc reason just good contrast between inside the eye and outside)
Igray = Irgb[:,:,0]
# Run median filter to reduce noise
IgrayFilter = cv2.medianBlur(Igray,101)
# Find circles using hough circles
minRadius = np.floor(np.min(Igray.shape)/2)
circles = cv2.HoughCircles(IgrayFilter, cv2.HOUGH_GRADIENT, dp=0.5,param1=100,param2=50,minRadius=int(minRadius),minDist=100)
circles = np.uint16(np.around(circles))
cimg = Irgb
# For each circle that we found find the intinestiy values inside the circle and outside.
# We eould take the circle that as the biggest difference between inside and outside
diff = []
for i in circles[0, :]:
# Create mask from circel identity
mask = np.zeros_like(Igray)
maskInverse = np.ones_like(Igray)
cv2.circle(mask, (i[0], i[1]), i[2], 1, cv2.FILLED)
cv2.circle(maskInverse, (i[0], i[1]), i[2], 0, cv2.FILLED)
# Find values inside mask and outside
insideMeanValues = np.mean(np.multiply(mask,Igray))
outsideMeanValues = np.mean(np.multiply(maskInverse, Igray))
# Save differnses
diff.append(abs(insideMeanValues-outsideMeanValues))
# Take the circle with the biggest difference in color as the border circle
circleID = np.argmax(diff)
circleInfo = circles[0, circleID]
# Create mask from final image
mask = np.zeros_like(Igray)
cv2.circle(mask, (i[0], i[1]), i[2], 1, cv2.FILLED)
# Show final image only in the mask
finalImage = Irgb
finalImage[:,:,0] = np.multiply(finalImage[:,:,0],mask)
finalImage[:,:,1] = np.multiply(finalImage[:,:,1],mask)
finalImage[:,:,2] = np.multiply(finalImage[:,:,2],mask)
cv2.imwrite('circle.jpg',finalImage)
相關問題
- 1. 如何減少圖像中的噪音
- 2. php - imagemagick用黑色掩蓋圖像
- 3. opencv的 - 掩蓋了黑色圖像的圖像效果
- 4. 圖像噪音去除
- 5. 如何在IOS sdk中掩蓋圖像?
- 6. ImageMagick - 單色噪音
- 7. 灰色UIImage - 灰色IP圖像轉換
- 8. SVG圖像掩蓋了IE
- 9. 如何從彩色圖像動畫到灰色圖像?
- 10. 如何獲取圖像中像素的顏色(加載灰色)?
- 11. 如何用KineticJS將另一個PNG圖像掩蓋PNG圖像?
- 12. 如何顯示灰色圖像的顏色圖?
- 13. :覆蓋前沒有掩蓋圖像時掩藏在
- 14. 什麼是常用來消除噪音和平滑的灰度圖像?
- 15. CSS:如何將彩色圖像變成灰色或黑色/白色圖像
- 16. 可可棕色噪音
- 17. 着色灰度圖像as3
- 18. '灰色'WPF按鈕圖像?
- 19. 着色灰度圖像
- 20. CSS - 着色灰度圖像
- 21. 如何識別圖像中存在的噪音類型
- 22. 如何添加和刪除圖像中的噪音
- 23. 如何使用OpenCV從圖像中去除特定的噪音
- 24. 如何掩蓋matlab中的圖像的一部分?
- 25. openCV顯示圖像灰色如果getchar
- 26. 如何掩蓋UIView
- 27. 用CSS/border-radius掩蓋圖像
- 28. 通過圖像掩蓋創建粒子
- 29. 使用路徑掩蓋圖像
- 30. 在Swift 2.0中掩蓋圖像
這是不是一個一般的用例? – meetaig