PIL的图像坐标索引是否颠倒了?它被索引为image [column,row]吗?
我有一个使用PIL(枕头)打开的图像
img = Image.open('picture.png').load()
Run Code Online (Sandbox Code Playgroud)
当我尝试打印第一行第二列的像素值时
print(img[0,1])
Run Code Online (Sandbox Code Playgroud)
我得到第二行第一列的像素值
谁能解决这个问题?
我有两个二值图像,我试图检测其中白色斑块的轮廓(拼贴右侧的粉红色轮廓是轮廓结果)。
cv2.contourFind() Contour1 工作正常:

但是对于 Contour2,它的表现很奇怪:

这是它的函数调用
#Convert Image to grayscale
img = cv2.imread(file_name)
img2gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(img2gray, 0, 255, cv2.THRESH_OTSU + cv2.THRESH_BINARY_INV)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
dilated = cv2.dilate(mask, kernel, iterations=2)
image, contours, hierarchy = cv2.findContours(dilated.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
for contour in contours:
[x, y, w, h] = cv2.boundingRect(contour)
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 255), 2)
Run Code Online (Sandbox Code Playgroud)
使用这个contours变量,我围绕找到的点绘制矩形。我不明白为什么它适用于 Contour1,但在它们看起来非常相似时却无法用于 Contour2。
在Python3.4中我有一个元组
t = ('A', 'B', 'C')
Run Code Online (Sandbox Code Playgroud)
和一份清单
l = ['P', 'Q', 'R']
Run Code Online (Sandbox Code Playgroud)
我需要将元组转换为格式化为的字符串,"(#A;#B;#C)"并将列表转换为格式为的字符串"(@P; @Q; @R)".显而易见的方法是使用for循环和字符串操作遍历.
有没有办法在不运行循环的情况下完成它?
谢谢!
python ×3
python-3.x ×2
formatting ×1
hotkeys ×1
opencv ×1
pillow ×1
python-3.4 ×1
tkinter ×1
vision ×1