opencv_threshold.py 373 B

12345678910111213141516
  1. import cv2
  2. def test22():
  3. src = cv2.imread("test1.jpg")
  4. # 灰度图片转换
  5. gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
  6. # 二进制阈值化处理
  7. r, b = cv2.threshold(gray, 155, 255, cv2.THRESH_BINARY)
  8. # 显示图像
  9. cv2.imshow("src", src)
  10. cv2.imshow("result", b)
  11. print(r)
  12. if cv2.waitKey(0) == 27:
  13. cv2.destroyAllWindows()
  14. test22()