我正在尝试启动网络摄像头并使用python捕获图像我使用了以下代码
@media (min-width: 601px) {
.desktop-hide {
display: none !important;
}
}
@media (max-width: 600px) {
.mobile-hide {
display: none !important;
}
}
* {
box-sizing: border-box;
}
.wrapper {
border: 1px solid seagreen;
max-width: 800px;
display: flex;
flex-flow: column wrap;
align-items: center;
}
.main {
display: flex;
flex-flow: row;
max-width: 600px;
min-width: 550px;
border: 1px solid orangered;
}
.timer {
display: flex;
justify-content: center;
}
.left-col, .right-col {
max-width: 300px;
}
* {
box-sizing: border-box;
}
.team {
background: chartreuse;
}
.score {
background: brown;
}
.scorers {
background: steelblue;
}
.cards-desktop {
background: goldenrod;
}
.carded-players {
background: darkorange;
}
.left-col, .right-col {
width: 80%;
margin: auto;
}
.left-col * >, .right-col * > {
display: flex;
}
.top > div {
padding: 5px;
}
.bottom > div {
height: 25px;
}
.top {
display: flex;
flex-flow: column wrap;
height: 100px;
}
.team,
.scorers {
height: 50%;
width: 75%;
}
.score {
width: 25%;
display: flex;
flex: 0 0 100%;
align-items: center;
justify-content: center;
font-size: 28px;
}
@media (max-width: 600px) {
.main {
min-width: 100%;
}
.top {
flex-flow: column nowrap;
height: initial;
}
.team, .scorers {
height: initial;
width: 100%;
}
.score {
flex: 1 100px;
align-self: flex-end;
}
.scorers {
order: 1;
}
}
.right-col .score {
align-self: flex-end;
}
.right-col .top {
flex-flow: column wrap-reverse;
}
.left-col .top > *:not(.score), .left-col .bottom > * {
display: flex;
justify-content: flex-end;
}
.team, .scorers {
display: flex;
align-items: center;
}
.empty {
height: 28px;
}
.colon {
height: 95px;
display: flex;
justify-content: center;
align-items: center;
font-size: 100px;
}
.corners {
display: flex;
flex-flow: row;
width: 100%;
justify-content: space-between;
}
.corner-left, .corner-right {
border: 1px solid crimson;
}
启动相机并在按下Esc时关闭,但不捕捉图像。我是否缺少捕获图像的命令?
答案 0 :(得分:0)
这段代码可以使用,我只需添加cv2.imwrite并保存你已经使用的帧。如果按下escape,该命令将写入图像:
import cv2
cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
if vc.isOpened(): # try to get the first frame
rval, frame = vc.read()
else:
rval = False
while rval:
cv2.imshow("preview", frame)
rval, frame = vc.read()
key = cv2.waitKey(20)
if key == 27: # exit on ESC
cv2.imwrite("image.png", frame)
break
cv2.destroyWindow("preview")
[编辑:] 确保您使用的是cv2而不是cv,我已更正您的导入语句。您使用的是哪个版本的OpenCV?