小编Vee*_*jay的帖子

cv2.videoCapture.release() 是什么意思?

我正在使用树莓派来捕获视频的前 20 帧。现在这更像是一个概念问题,但是在浏览关于 videoCapture 的 openCV 文档时,他们强调了在此代码中发布捕获的重要性(如其网站上发布的那样):

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

的重要性是cap.release()什么?省略这一行是否有任何记忆含义?如果是,它们是什么,为什么?

python opencv raspberry-pi

6
推荐指数
2
解决办法
2万
查看次数

将边界框的内容保存为新图像 - opencv python

我正在尝试使用一个代码片段,该代码片段使用opencv来识别图像中最大的轮廓/对象.下面的代码成功创建了边界框,但是将边界框保存为单独图像的最佳方法是什么,因此我可以将图像中的最大对象存储为新的jpg文件.这是我正在使用的代码:

import numpy as np
import cv2

font = cv2.FONT_HERSHEY_SIMPLEX
lineType = cv2.LINE_AA

im = cv2.imread('test/originals/8.jpg')
im_ycrcb = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)

ball_ycrcb_mint = np.array([0, 90, 100],np.uint8)
ball_ycrcb_maxt = np.array([25, 255, 255],np.uint8)
ball_ycrcb = cv2.inRange(im_ycrcb, ball_ycrcb_mint, ball_ycrcb_maxt)
cv2.imwrite('test/outputs/output8.jpg', ball_ycrcb) # Second image
areaArray = []
count = 1

_, contours, _ = cv2.findContours(ball_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for i, c in enumerate(contours):
    area = cv2.contourArea(c)
    areaArray.append(area)
    areaLargest = np.argmax(areaArray)
    areaLargestMax = max(areaArray)
    areaLargestCnt = contours[areaLargest]
    x, y, w, h = cv2.boundingRect(areaLargestCnt)
    roi = im …
Run Code Online (Sandbox Code Playgroud)

python opencv

2
推荐指数
1
解决办法
4674
查看次数

在没有扩展名的目录中获取文件名 - Python

我试图在没有获得扩展名的情况下获取目录中的文件名。使用我当前的代码 -

import os

path = '/Users/vivek/Desktop/buffer/xmlTest/' 
files = os.listdir(path) 
print (files)
Run Code Online (Sandbox Code Playgroud)

我最终得到这样的输出:

['img_8111.jpg', 'img_8120.jpg', 'img_8127.jpg', 'img_8128.jpg', 'img_8129.jpg', 'img_8130.jpg']
Run Code Online (Sandbox Code Playgroud)

但是我希望输出看起来更像这样:

['img_8111', 'img_8120', 'img_8127', 'img_8128', 'img_8129', 'img_8130']
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

python

2
推荐指数
1
解决办法
8335
查看次数

将.write函数与多个参数一起使用以写入txt文件-Python

我正在尝试将以下循环写入.txt文件(除了将输出打印到终端)。这样做时,我会看到一条错误消息:

> TypeError:function takes exactly 1 argument (2 given)
Run Code Online (Sandbox Code Playgroud)

我了解错误试图传达的内容,但是有办法解决此问题。我确实需要标签并将结果输出到.txt文件,就像它们打印在终端上一样

这是我正在使用的代码:

out_write = open(write_to, 'wb')

for arr in top_k:
    print(labels[arr], results[arr])
    out_write.write(labels[arr], results[arr])
print ("\n\n\n")
out_write("\n\n\n")
out_write.close()
Run Code Online (Sandbox Code Playgroud)

我正在使用python 2.7

python

1
推荐指数
1
解决办法
947
查看次数

标签 统计

python ×4

opencv ×2

raspberry-pi ×1