我正在编写一个opencv程序,我在另一个stackoverflow问题上找到了一个脚本:计算机视觉:屏蔽人手
当我运行脚本的答案时,我收到以下错误:
Traceback (most recent call last):
File "skinimagecontour.py", line 13, in <module>
contours, _ = cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
ValueError: too many values to unpack
Run Code Online (Sandbox Code Playgroud)
代码:
import sys
import numpy
import cv2
im = cv2.imread('Photos/test.jpg')
im_ycrcb = cv2.cvtColor(im, cv2.COLOR_BGR2YCR_CB)
skin_ycrcb_mint = numpy.array((0, 133, 77))
skin_ycrcb_maxt = numpy.array((255, 173, 127))
skin_ycrcb = cv2.inRange(im_ycrcb, skin_ycrcb_mint, skin_ycrcb_maxt)
cv2.imwrite('Photos/output2.jpg', skin_ycrcb) # Second image
contours, _ = cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for i, c in enumerate(contours):
area = cv2.contourArea(c)
if area > 1000:
cv2.drawContours(im, contours, …Run Code Online (Sandbox Code Playgroud) 我有一个图像,想要检测其中的文本区域.
我试过TiRG_RAW_20110219项目,但结果并不理想.如果输入图像是http://imgur.com/yCxOvQS,GD38rCa,则它将生成http://imgur.com/yCxOvQS,GD38rCa#1作为输出.
谁能提出一些替代方案.我想通过仅将文本区域作为输入发送来改善tesseract的输出.
我有一个固定相机,可以快速拍摄连续移动的产品的照片,但处于相同角度(平移视角)的固定位置。我需要将所有图像拼接成全景图。我尝试过使用 Stitcher 类。它有效,但计算时间很长。我还尝试使用另一种方法,即使用 SIFT 检测器 FNNbasedMatcher,查找单应性,然后扭曲图像。如果我只使用两个图像,此方法效果很好。对于多个图像,它仍然无法正确缝合它们。有谁知道这种情况下最好、最快的图像拼接算法?
这是我使用 Stitcher 类的代码。
import time
import cv2
import os
import numpy as np
import sys
def main():
# read input images
imgs = []
path = 'pics_rotated/'
i = 0
for (root, dirs, files) in os.walk(path):
images = [f for f in files]
print(images)
for i in range(0,len(images)):
curImg = cv2.imread(path + images[i])
imgs.append(curImg)
stitcher = cv2.Stitcher.create(mode= 0)
status ,result = stitcher.stitch(imgs)
if status != cv2.Stitcher_OK:
print("Can't stitch images, error code = %d" % …Run Code Online (Sandbox Code Playgroud) python opencv image-processing computer-vision image-stitching
我正在制作一个可修复扫描文档的脚本,现在我需要一种方法来检测图像方向并旋转图像,以便其旋转正确。
目前,我的脚本不可靠,不够精确。
现在我正在寻找一条线,它会旋转正确看到的第一条线,但是除了几张图像外,这几乎行不通
img_before = cv2.imread('rotated_377.jpg')
img_gray = cv2.cvtColor(img_before, cv2.COLOR_BGR2GRAY)
img_edges = cv2.Canny(img_gray, 100, 100, apertureSize=3)
lines = cv2.HoughLinesP(img_edges, 1, math.pi / 180.0, 100, minLineLength=100, maxLineGap=5)
angles = []
for x1,y1,x2,y2 in lines[0]:
angle = math.degrees(math.atan2(y2 - y1, x2 - x1))
angles.append(angle)
median_angle = np.median(angles)
img_rotated = ndimage.rotate(img_before, median_angle)
print("Angle is {}".format(median_angle))
cv2.imwrite('rotated.jpg', img_rotated)
Run Code Online (Sandbox Code Playgroud)
并以正确的方式旋转它,以便获得正确定向的图像。
我是一个蟒蛇初学者.我试图运行此代码:
#applying closing function
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (7, 7))
closed = cv2.morphologyEx(th3, cv2.MORPH_CLOSE, kernel)
#finding_contours
(cnts, _) = cv2.findContours(closed.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in cnts:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
cv2.drawContours(frame, [approx], -1, (0, 255, 0), 2)
Run Code Online (Sandbox Code Playgroud)
当我召唤mask.py时,我得到了这个ValueError:
Traceback (most recent call last):
File "mask.py", line 22, in <module>
(cnts, _) = cv2.findContours(closed.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
ValueError: too many values to unpack
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题?