Description
Issue №2010 opened by t-walker-wei at 2020-07-09 09:04:47
Now, I connect 2 Usb camers which are the same to Raspberry 4 B+, use Raspberry Pi OS base on Debian Buster.
pygame version:1.9.4.post1
When I try to capture from cameras one by one, it will blocked in the second camera when cal get_image() function.
Here is my code from :https://gist.github.com/ereli/c9998a6911c2f426cd41dd85c99cda7a
import time
from pathlib import Path
import pygame
import pygame.camera
from pygame.locals import *
from datetime import datetime
pygame.init()
pygame.camera.init()
try:
pygame.camera.list_cameras() # Camera detected or not
except:
raise("couldn't read camera")
cam_list = ['cam0', 'cam1']
actual_cam_list = ['/dev/video0','/dev/video2']
active_cameras = []
for x, y in zip(actual_cam_list, cam_list):
globals()[y] = pygame.camera.Camera(
x, (640, 480)) # generate_function(x,'data/')
globals()[y].start()
active_cameras.append(globals()[y])
def init(folder):
folder_path = Path(folder).resolve()
try:
folder_path.mkdir(exist_ok=False)
except FileExistsError:
pass
def capture(camera, folder="data/"):
t = time.localtime()
folder_path = Path(folder).resolve()
init(folder)
# print(camera)
img = camera.get_image()
now = datetime.now()
timestamp = now.strftime("%H:%M:%S.%f")
out_file = str(folder_path.joinpath(
"img_{0}.jpg".format(timestamp)).absolute())
print("Saving filename: {0}".format(out_file))
pygame.image.save(img, out_file)
if __name__ == '__main__':
for i in active_cameras:
capture(i)
Comments
# # MyreMylar commented at 2020-07-09 15:16:37
That is quite an old version of pygame.
I know it is possible to capture from multiple cameras simultaneously on windows in a recent version of pygame. My advice would be to update your version of pygame to 2.0.0.dev10 and try again.
# # illume commented at 2020-07-09 21:31:22
Another thing to try is to see if you can use other camera apps at the same
time? This would help narrow it down.
On Thursday, July 9, 2020, Dan Lawrence notifications@github.com wrote:
That is quite an old version of pygame.
I know it is possible to capture from multiple cameras simultaneously on
windows in a recent version of pygame. My advice would be to update your
version of pygame to 2.0.0.dev10 and try again.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<pygame/pygame#2010 issuecomment-656189030>, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AAACKRKK7XGLVMBCRNRUBZTR2XNOJANCNFSM4OVMMJUA
.
# # t-walker-wei commented at 2020-07-10 01:38:35
That is quite an old version of pygame.
I know it is possible to capture from multiple cameras simultaneously on windows in a recent version of pygame. My advice would be to update your version of pygame to 2.0.0.dev10 and try again.
I have installed pygame2.0.0.dev10, still got blocked.
# # t-walker-wei commented at 2020-07-10 01:40:16
Another thing to try is to see if you can use other camera apps at the same time? This would help narrow it down.
…
On Thursday, July 9, 2020, Dan Lawrence @.***> wrote: That is quite an old version of pygame. I know it is possible to capture from multiple cameras simultaneously on windows in a recent version of pygame. My advice would be to update your version of pygame to 2.0.0.dev10 and try again. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <[# 2010 (comment)](pygame/pygame#2010 issuecomment-656189030)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACKRKK7XGLVMBCRNRUBZTR2XNOJANCNFSM4OVMMJUA .
Cannot, it showed Resource busy.
# # illume commented at 2020-07-10 10:03:42
Hi,
ok, so i guess it’s a video4linux thing.
On Friday, July 10, 2020, Walker notifications@github.com wrote:
Cannot, it showed Resource busy.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<pygame/pygame#2010 issuecomment-656433743>, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AAACKRM2Z42GA5QA2C6GEQDR2ZWQZANCNFSM4OVMMJUA
.
# # MyreMylar commented at 2020-10-18 11:03:32
Would be good to get confirmation from another user on linux with two web cams.
# # bydariogamer commented at 2021-12-02 08:30:57
I don't get that issue with a webcam and a virtual cam:
~$ python3
Python 3.9.9 (main, Nov 24 2021, 13:56:55)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> from pathlib import Path
>>> import pygame
pygame 2.1.1.dev1 (SDL 2.0.19, Python 3.9.9)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> import pygame.camera
>>> from pygame.locals import *
>>> from datetime import datetime
>>>
>>> pygame.init()
(5, 0)
>>> pygame.camera.init()
>>>
>>> try:
... pygame.camera.list_cameras() # Camera detected or not
... except:
... raise("couldn't read camera")
...
['/dev/video0', '/dev/video1', '/dev/video2']
>>> for x, y in zip(actual_cam_list, cam_list):
... globals()[y] = pygame.camera.Camera(
... x, (640, 480)) # generate_function(x,'data/')
... globals()[y].start()
... active_cameras.append(globals()[y])
...
>>> cam_list = ['cam0', 'cam1']
>>> actual_cam_list = ['/dev/video0','/dev/video2']
>>> active_cameras = []
>>> for x, y in zip(actual_cam_list, cam_list):
... globals()[y] = pygame.camera.Camera(
... x, (640, 480)) # generate_function(x,'data/')
... globals()[y].start()
... active_cameras.append(globals()[y])
...
>>> def init(folder):
... folder_path = Path(folder).resolve()
... try:
... folder_path.mkdir(exist_ok=False)
... except FileExistsError:
... pass
...
>>> def capture(camera, folder="data/"):
... t = time.localtime()
... folder_path = Path(folder).resolve()
... init(folder)
... # print(camera)
... img = camera.get_image()
... now = datetime.now()
... timestamp = now.strftime("%H:%M:%S.%f")
... out_file = str(folder_path.joinpath(
... "img_{0}.jpg".format(timestamp)).absolute())
... print("Saving filename: {0}".format(out_file))
... pygame.image.save(img, out_file)
...
>>> for i in active_cameras:
... capture(i)
...
Saving filename: /home/foobar/data/img_09:26:44.966588.jpg
Saving filename: /home/foobar/data/img_09:26:44.982491.jpg
>>> for i in active_cameras:
... capture(i)
...
Saving filename: /home/foobar/data/img_09:27:22.068762.jpg
Saving filename: /home/foobar/data/img_09:27:22.074696.jpg