这一行:
sift = cv2.xfeatures2d.SIFT_create()
Run Code Online (Sandbox Code Playgroud)
返回错误:
Traceback (most recent call last):
File "C:/Python27/openCVskrypty/GUI/SOLUTION2.py", line 11, in <module>
sift = cv2.xfeatures2d.SIFT_create()
AttributeError: 'module' object has no attribute 'xfeatures2d'
Run Code Online (Sandbox Code Playgroud)
我读了一些关于这个错误的内容,它出现在OpenCV 3.0版中.这很奇怪,因为我有2.4.11版本.
我检查dir(cv2),我没有xfeatures2d模块.有谁知道为什么?我可以单独下载吗?
感谢您帮忙解决这个问题.
我想用Python创建一个脚本(使用OpenCV库)来确定图片中的标记.标记看起来像这样:
加载图像后,脚本应该打印图片中的标记(返回标记数).例如,如果我加载这张图片:
对于这个图像,脚本应该返回三个数字:1,2和3.我有一个脚本,它加载图像并识别图形(圆形,正方形等 - 在下面的脚本中只有正方形)但我不知道整个标记,由几个数字组成.有任何想法吗?请提供有关算法或任何解决方案的任何建议.
import numpy as np
import cv2
img = cv2.imread('B.jpg')
gray = cv2.imread('B.jpg',0)
ret,thresh = cv2.threshold(gray,120,255,1)
contours,h = cv2.findContours(thresh,1,2)
for cnt in contours:
approx = cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True)
print len(approx)
if len(approx)==4:
print "square"
cv2.drawContours(img,[cnt],0,(0,0,255))
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
但显然它不是我需要它只围绕矩形.感谢您的任何提示和帮助.
我尝试使用 Moravec 检测。当我尝试运行此代码时,出现一些错误:
diff = diff - image.getpixel((x, y))
TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'
Run Code Online (Sandbox Code Playgroud)
我该如何修复它?任何帮助将不胜感激。代码是:
def moravec(image, threshold = 100):
"""Moravec's corner detection for each pixel of the image."""
corners = []
xy_shifts = [(1, 0), (1, 1), (0, 1), (-1, 1)]
for y in range(1, image.size[1]-1):
for x in range(1, image.size[0]-1):
# Look for local maxima in min(E) above threshold:
E = 100000
for shift in xy_shifts:
diff = image.getpixel((x + shift[0], y + shift[1])) …Run Code Online (Sandbox Code Playgroud) 我在Tkinter的文本小部件内的滚动条中设置有问题。我知道,最好使用网格来定位小部件,但是我想将小部件设置为具有指定高度和宽度的绝对位置(x,y-GUI图片上的红点)。
我的代码:
from Tkinter import *
from ttk import *
class NotebookDemo(Frame):
def __init__(self):
Frame.__init__(self)
self.pack(expand=1, fill=BOTH)
self.master.title('Sample')
self.master.geometry("650x550+100+50")
self._initUI()
def _initUI(self):
self._createPanel()
def _createPanel(self):
# create frame inside top level frame
panel = Frame(self)
panel.pack(side=TOP, fill=BOTH, expand=1)
# create the notebook
nb = Notebook(panel)
nb.pack(fill=BOTH, expand=1, padx=2, pady=3)
self._FirstTab(nb)
def _FirstTab(self, nb):
# frame to hold content
frame = Frame(nb)
#textbox
txtOutput = Text(frame, wrap = NONE, height = 17, width = 70)
txtOutput.place(x=10, y=75)
#button
btnStart = Button(frame, …Run Code Online (Sandbox Code Playgroud)