python识别图片坐标查看器_Opencv/python图像处理后如何获取检测区域的坐标
這是我使用的代碼。最后,我不得不重新調整我的數據幀,但只是為了更好地閱讀。我認為我的代碼有很多可能的改進,但是我很高興我的代碼行為足夠好地滿足我的需要。在import cv2
import numpy as np
import pandas as pd
img = cv2.imread('full_snap.png')
"""
some of my blue pixels
R: between 98 and 128
G: between 176 and 211
B: between 255
h: between 210 and 200
s: between 100 and 48
v: between 68 and 100
hsv/2 in opencv and opencv uses BGR not RGB
"""
blue_MIN = np.array([255, 176, 98])
blue_MAX = np.array([255, 211, 128])
"""
https://pythonprogramming.net/color-filter-python-opencv-tutorial/
"""
# find the blue pixels and save it in frame_threshed
frame_threshed = cv2.inRange(img, blue_MIN, blue_MAX)
# find contours in the thresholded image
cnts = cv2.findContours(frame_threshed.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
#print("cnts", cnts)
i = len(cnts)
print("i", i)
# we know we're gonna have x rows of data, where x is the product of
# board_width * board_height
numberOfRows = 81
# check if the length of cnts are euqal to the number of rows/ number of tiles
# then go further
# TODO
# create x,y data
# df = pd.DataFrame(index=np.arange(numberOfRows, 0), columns=('x', 'y'))
d = []
print("d", d)
print(type(d))
for c in cnts:
# compute the center of the contour
M = cv2.moments(c)
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
# fill the data with the coords
d.append({'tilenumber': i, 'X-Value': cX, 'Y-Value': cY})
# decrease i to go backwards, because tile number 81 is the first contour
i-=1
# draw the center of the shape on the image
cv2.circle(img, (cX, cY), 1, (255, 255, 255), -1)
df = pd.DataFrame(d)
# only for debugging
print("x,y dataframe", df)
cv2.imshow("Image_with_contours",img)
# Destroys all of the HighGUI windows.
cv2.destroyAllWindows()
謝謝大家的幫助!
羅比納圖爾
總結
以上是生活随笔為你收集整理的python识别图片坐标查看器_Opencv/python图像处理后如何获取检测区域的坐标的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 内存颗粒:让设备速度翻倍,顶尖性能引领全
- 下一篇: 内存超频,性能提升不止一点点