为什么用Python拍摄的网络摄像头图像如此黑暗?
我以各种方式展示了如何使用Python中的网络摄像头拍摄图像(请参阅)。您可以看到,使用Python拍摄的图像比使用JavaScript拍摄的图像暗得多。怎么了 图像示例 左边的图片是用Python代码拍摄的,右边的图片是用Python代码拍摄的。这两张照片都是在相同的(受控的)闪电情况下拍摄的(外面很黑,我只打开了一些电灯)和相同的网络摄像头 代码示例 问题: 为什么使用Python图像拍摄的图像比使用JavaScript拍摄的图像要暗得多?我该如何修复它 (获得类似的图像质量;仅仅使其更亮可能无法修复。)为什么用Python拍摄的网络摄像头图像如此黑暗?,python,opencv,Python,Opencv,我以各种方式展示了如何使用Python中的网络摄像头拍摄图像(请参阅)。您可以看到,使用Python拍摄的图像比使用JavaScript拍摄的图像暗得多。怎么了 图像示例 左边的图片是用Python代码拍摄的,右边的图片是用Python代码拍摄的。这两张照片都是在相同的(受控的)闪电情况下拍摄的(外面很黑,我只打开了一些电灯)和相同的网络摄像头 代码示例 问题: 为什么使用Python图像拍摄的图像比使用JavaScript拍摄的图像要暗得多?我该如何修复它 (获得类似的图像质量;仅仅使其更亮
注意“如何修复它”:它不需要是opencv。如果您知道可以使用Python(或不带软件包)拍摄网络摄像头图像,也可以。我认为您必须等待摄像头准备就绪 此代码适用于我:
from SimpleCV import Camera
import time
cam = Camera()
time.sleep(3)
img = cam.getImage()
img.save("simplecv.png")
这是我发现的最有说服力的解释:
在某些设备上,前几帧是黑色的,因为这是第一帧
初始化相机后的帧,可能需要拉动
减少帧数,以便相机有时间调整亮度
自动地
因此,为了确保图像质量,无论编程语言如何,IMHO在启动相机设备时都必须等待几秒钟和/或放弃几帧,然后再拍摄图像。面临同样的问题。我试过这个,效果很好
import cv2
camera_port = 0
ramp_frames = 30
camera = cv2.VideoCapture(camera_port)
def get_image():
retval, im = camera.read()
return im
for i in xrange(ramp_frames):
temp = camera.read()
camera_capture = get_image()
filename = "image.jpg"
cv2.imwrite(filename,camera_capture)
del(camera)
我认为这是关于调整相机的光线。前者
图像整理Keerthana的答案会导致我的代码如下所示
import cv2
import time
def main():
capture = capture_write()
def capture_write(filename="image.jpeg", port=0, ramp_frames=30, x=1280, y=720):
camera = cv2.VideoCapture(port)
# Set Resolution
camera.set(3, x)
camera.set(4, y)
# Adjust camera lighting
for i in range(ramp_frames):
temp = camera.read()
retval, im = camera.read()
cv2.imwrite(filename,im)
del(camera)
return True
if __name__ == '__main__':
main()
我猜
camera.read()
有一些参数来控制摄像机设置。你查过了吗?(帮助(camera.read)
)@septi:它没有。请参见外观相关:@septi:我确实查看了,没有其他参数。同样,外观相关:为什么使用range而不是xrange?它也可以用于Python 3好主意!代码已修改为在Python2和Python3中工作^_^
import cv2
import time
def main():
capture = capture_write()
def capture_write(filename="image.jpeg", port=0, ramp_frames=30, x=1280, y=720):
camera = cv2.VideoCapture(port)
# Set Resolution
camera.set(3, x)
camera.set(4, y)
# Adjust camera lighting
for i in range(ramp_frames):
temp = camera.read()
retval, im = camera.read()
cv2.imwrite(filename,im)
del(camera)
return True
if __name__ == '__main__':
main()