我的简单python代码是这样的
import cv2
img=cv2.imread('Materials/shapes.png')
blur=cv2.GaussianBlur(img,(3,3),0)
gray=cv2.cvtColor(blur,cv2.COLOR_BGR2GRAY)
returns,thresh=cv2.threshold(gray,80,255,cv2.THRESH_BINARY)
ret,contours,hierachy=cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
area=cv2.contourArea(cnt) #contour area
if (area>1220):
cv2.drawContours(img,[cnt],-1,(0,255,0),2)
cv2.imshow('RGB',img)
cv2.waitKey(1000)
print(len(cnt))
import numpy as np
contours=np.array(contours)
print(contours)
Run Code Online (Sandbox Code Playgroud)
这很好.但最近没有我做任何改变.这是扔给我的
RET,轮廓,层次结构= cv2.findContours(THRESH,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
ValueError:没有足够的值来解压缩(预期3,得到2)
帮帮我们
谢谢.
我正在尝试使用常规网络摄像头确定骨架关节(或者至少能够跟踪单个手掌).我在网上看了一遍,似乎无法找到办法.
我发现的每个例子都是使用Kinect.我想使用一个网络摄像头.
我不需要计算关节的深度 - 我只需要能够识别它们在框架中的X,Y位置.这就是我使用网络摄像头而不是Kinect的原因.
到目前为止,我已经看过了:
我正在寻找一个C/C++库(但此时会查看任何其他语言),最好是开源(但同样,会考虑任何许可),可以执行以下操作:
如果有人可以帮我解决这个问题,我将非常感激.我已经被困在这几天了,没有明确的道路可以继续.
UPDATE
2年后,找到了一个解决方案:http://dlib.net/imaging.html#shape_predictor
我正在使用openCv和python,我正在处理结构分析和形状描述符.我找到了这个博客:http://opencvpython.blogspot.it/2012/06/contours-2-brotherhood.html 这是非常有帮助的,我尝试用黑白图像绘制一个边界矩形,它的工作原理.但是现在从我提取的图像,例如,黄色和我想要绘制一个边界矩形.问题是黑白图像不均匀,有一些噪音,而且代码不能识别整个形状.



这是代码:
import numpy as np
import cv2
im = cv2.imread('shot.bmp')
hsv_img = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)
COLOR_MIN = np.array([20, 80, 80],np.uint8)
COLOR_MAX = np.array([40, 255, 255],np.uint8)
frame_threshed = cv2.inRange(hsv_img, COLOR_MIN, COLOR_MAX)
imgray = frame_threshed
ret,thresh = cv2.threshold(frame_threshed,127,255,0)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cnt=contours[0]
x,y,w,h = cv2.boundingRect(cnt)
cv2.rectangle(im,(x,y),(x+w,y+h),(0,255,0),2)
cv2.imshow("Show",im)
cv2.waitKey()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud) 通常在OCR的过程中,图像文件基本上被切割成段,并且每个字符被重新称为段.例如,
必须转变成类似的东西

此外,是否有像泰卢固语这样的亚洲语言的算法可以用于此目的?如果没有,这对英语怎么办?
我想从实时视频流中检测到我的手并创建一个我的手的面具.然而,正如你从图片中看到的那样,我的结果非常糟糕.
我的目标是跟踪手的运动,所以我所做的就是从BGR转换视频流HSV色彩空间,然后我为了我的手的颜色隔离阈值处理的图像,然后我试图找到我的手的轮廓,虽然最终的结果并不是我想要实现的目标.
我怎样才能改善最终结果?
import cv2
import numpy as np
cam = cv2.VideoCapture(1)
cam.set(3,640)
cam.set(4,480)
ret, image = cam.read()
skin_min = np.array([0, 40, 150],np.uint8)
skin_max = np.array([20, 150, 255],np.uint8)
while True:
ret, image = cam.read()
gaussian_blur = cv2.GaussianBlur(image,(5,5),0)
blur_hsv = cv2.cvtColor(gaussian_blur, cv2.COLOR_BGR2HSV)
#threshould using min and max values
tre_green = cv2.inRange(blur_hsv, skin_min, skin_max)
#getting object green contour
contours, hierarchy = cv2.findContours(tre_green,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#draw contours
cv2.drawContours(image,contours,-1,(0,255,0),3)
cv2.imshow('real', image)
cv2.imshow('tre_green', tre_green)
key = cv2.waitKey(10)
if key == 27:
break
Run Code Online (Sandbox Code Playgroud)
这里是图片链接:https://picasaweb.google.com/103610822612915300423/February7201303.带图像的新链接以及轮廓,蒙版和原始图像. …
我是 Python 新手,但想学一点,所以我决定创建一个与桌面输入进行模板匹配的程序。
有人能帮忙吗 ?如何编写与桌面流匹配的模板?
import time
import cv2
import mss
import numpy
template = cv2.imread('template.jpg', 0)
w, h = template.shape[::-1]
with mss.mss() as sct:
# Part of the screen to capture
monitor = {"top": 40, "left": 0, "width": 800, "height": 640}
while "Screen capturing":
last_time = time.time()
# Get raw pixels from the screen, save it to a Numpy array
img = numpy.array(sct.grab(monitor))
# Display the picture
# cv2.imshow("OpenCV/Numpy normal", img)
# Display the picture in grayscale
cv2.imshow('OpenCV/Numpy grayscale', …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行网站代码来创建图像。
当我运行代码时,它给我一个错误:
cv2.error: OpenCV(4.1.0)
/Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/shapedescr.cpp:274:
error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S)
in function 'contourArea'
Run Code Online (Sandbox Code Playgroud)
我不确定其背后的原因。
所以我正在尝试编译以下代码,但它显示了cv2.findContours上的错误.虽然,我使用的是Python 2.7版本.任何原因导致错误:解压缩python 2.7的值太多了?
import cv2
import numpy as np
import time
#Open Camera object
cap = cv2.VideoCapture(0)
#Decrease frame size
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1000)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 600)
def nothing(x):
pass
# Function to find angle between two vectors
def Angle(v1,v2):
dot = np.dot(v1,v2)
x_modulus = np.sqrt((v1*v1).sum())
y_modulus = np.sqrt((v2*v2).sum())
cos_angle = dot / x_modulus / y_modulus
angle = np.degrees(np.arccos(cos_angle))
return angle
# Function to find distance between two points in a list of lists
def FindDistance(A,B):
return np.sqrt(np.power((A[0][0]-B[0][0]),2) + np.power((A[0][1]-B[0][1]),2))
# Creating a …Run Code Online (Sandbox Code Playgroud) opencv ×7
python ×5
python-2.7 ×2
camera ×1
matlab ×1
ocr ×1
python-3.x ×1
tracking ×1
video ×1
webcam ×1