Cannot capture frames from two cameras (through one hub) simultaneously on windows using python cv2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
When trying to capture frames from two cameras (using a single USB hub) simultaneously, only one camera can return a valid frame, the other one will return None. When using one external camera and the internal camera from the laptop, it works fine.
The exact same code and hardware work fine on a Ubuntu system. So it might be problem with Windows or its driver, or there is something wrong using the hub (maybe bandwidth problem, but not power problem because the hub has external power supply)
import cv2
import numpy as np
from multiprocessing import Process
def show(camera_id):
cap = cv2.VideoCapture(camera_id)
cap.set(3,640)
cap.set(4,480)
cap.set(cv2.CAP_PROP_FPS, 30)
while True:
ret, frame = cap.read()
cv2.imshow('test', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
p1 = Process(target=show, args=(0,))
p2 = Process(target=show, args=(1,))
p1.start()
p2.start()
python camera cv2
add a comment |
When trying to capture frames from two cameras (using a single USB hub) simultaneously, only one camera can return a valid frame, the other one will return None. When using one external camera and the internal camera from the laptop, it works fine.
The exact same code and hardware work fine on a Ubuntu system. So it might be problem with Windows or its driver, or there is something wrong using the hub (maybe bandwidth problem, but not power problem because the hub has external power supply)
import cv2
import numpy as np
from multiprocessing import Process
def show(camera_id):
cap = cv2.VideoCapture(camera_id)
cap.set(3,640)
cap.set(4,480)
cap.set(cv2.CAP_PROP_FPS, 30)
while True:
ret, frame = cap.read()
cv2.imshow('test', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
p1 = Process(target=show, args=(0,))
p2 = Process(target=show, args=(1,))
p1.start()
p2.start()
python camera cv2
@HaBom thank you for your reply. The second process break at line 'ret, frame = cap.read()', so it may not be caused by the name of the windows. And this code works fine on my ubuntu machine.
– Wenbin Xu
Jan 4 at 6:29
I just realise that it's not the problem. I don't have 2 usb cameras, so I try with ip cameras and videos also, but there's nothing wrong with the code. I think maybe it's a bandwidth problem as you've mentioned. I've found another post with the same problem as yours stackoverflow.com/questions/29664399/…
– Ha Bom
Jan 4 at 6:56
@HaBom Thank you for your info. I'm not sure if both posts are referring to the same problem. In my case, multiple cameras can work on my workstation of my HP laptop if I insert them directly to usb ports on my machines. But if I use a usb hub and then connect two cameras to the same external hub, then this problem occurs. I checked that under both circumstances, both cameras are connected to the same usb bus (using 'lsusb'), so I'm a bit confused what may have caused my problem, seems like the hub is limiting the performance?
– Wenbin Xu
Jan 7 at 1:47
add a comment |
When trying to capture frames from two cameras (using a single USB hub) simultaneously, only one camera can return a valid frame, the other one will return None. When using one external camera and the internal camera from the laptop, it works fine.
The exact same code and hardware work fine on a Ubuntu system. So it might be problem with Windows or its driver, or there is something wrong using the hub (maybe bandwidth problem, but not power problem because the hub has external power supply)
import cv2
import numpy as np
from multiprocessing import Process
def show(camera_id):
cap = cv2.VideoCapture(camera_id)
cap.set(3,640)
cap.set(4,480)
cap.set(cv2.CAP_PROP_FPS, 30)
while True:
ret, frame = cap.read()
cv2.imshow('test', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
p1 = Process(target=show, args=(0,))
p2 = Process(target=show, args=(1,))
p1.start()
p2.start()
python camera cv2
When trying to capture frames from two cameras (using a single USB hub) simultaneously, only one camera can return a valid frame, the other one will return None. When using one external camera and the internal camera from the laptop, it works fine.
The exact same code and hardware work fine on a Ubuntu system. So it might be problem with Windows or its driver, or there is something wrong using the hub (maybe bandwidth problem, but not power problem because the hub has external power supply)
import cv2
import numpy as np
from multiprocessing import Process
def show(camera_id):
cap = cv2.VideoCapture(camera_id)
cap.set(3,640)
cap.set(4,480)
cap.set(cv2.CAP_PROP_FPS, 30)
while True:
ret, frame = cap.read()
cv2.imshow('test', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
p1 = Process(target=show, args=(0,))
p2 = Process(target=show, args=(1,))
p1.start()
p2.start()
python camera cv2
python camera cv2
edited Jan 4 at 6:25
Wenbin Xu
asked Jan 4 at 6:19
Wenbin XuWenbin Xu
33
33
@HaBom thank you for your reply. The second process break at line 'ret, frame = cap.read()', so it may not be caused by the name of the windows. And this code works fine on my ubuntu machine.
– Wenbin Xu
Jan 4 at 6:29
I just realise that it's not the problem. I don't have 2 usb cameras, so I try with ip cameras and videos also, but there's nothing wrong with the code. I think maybe it's a bandwidth problem as you've mentioned. I've found another post with the same problem as yours stackoverflow.com/questions/29664399/…
– Ha Bom
Jan 4 at 6:56
@HaBom Thank you for your info. I'm not sure if both posts are referring to the same problem. In my case, multiple cameras can work on my workstation of my HP laptop if I insert them directly to usb ports on my machines. But if I use a usb hub and then connect two cameras to the same external hub, then this problem occurs. I checked that under both circumstances, both cameras are connected to the same usb bus (using 'lsusb'), so I'm a bit confused what may have caused my problem, seems like the hub is limiting the performance?
– Wenbin Xu
Jan 7 at 1:47
add a comment |
@HaBom thank you for your reply. The second process break at line 'ret, frame = cap.read()', so it may not be caused by the name of the windows. And this code works fine on my ubuntu machine.
– Wenbin Xu
Jan 4 at 6:29
I just realise that it's not the problem. I don't have 2 usb cameras, so I try with ip cameras and videos also, but there's nothing wrong with the code. I think maybe it's a bandwidth problem as you've mentioned. I've found another post with the same problem as yours stackoverflow.com/questions/29664399/…
– Ha Bom
Jan 4 at 6:56
@HaBom Thank you for your info. I'm not sure if both posts are referring to the same problem. In my case, multiple cameras can work on my workstation of my HP laptop if I insert them directly to usb ports on my machines. But if I use a usb hub and then connect two cameras to the same external hub, then this problem occurs. I checked that under both circumstances, both cameras are connected to the same usb bus (using 'lsusb'), so I'm a bit confused what may have caused my problem, seems like the hub is limiting the performance?
– Wenbin Xu
Jan 7 at 1:47
@HaBom thank you for your reply. The second process break at line 'ret, frame = cap.read()', so it may not be caused by the name of the windows. And this code works fine on my ubuntu machine.
– Wenbin Xu
Jan 4 at 6:29
@HaBom thank you for your reply. The second process break at line 'ret, frame = cap.read()', so it may not be caused by the name of the windows. And this code works fine on my ubuntu machine.
– Wenbin Xu
Jan 4 at 6:29
I just realise that it's not the problem. I don't have 2 usb cameras, so I try with ip cameras and videos also, but there's nothing wrong with the code. I think maybe it's a bandwidth problem as you've mentioned. I've found another post with the same problem as yours stackoverflow.com/questions/29664399/…
– Ha Bom
Jan 4 at 6:56
I just realise that it's not the problem. I don't have 2 usb cameras, so I try with ip cameras and videos also, but there's nothing wrong with the code. I think maybe it's a bandwidth problem as you've mentioned. I've found another post with the same problem as yours stackoverflow.com/questions/29664399/…
– Ha Bom
Jan 4 at 6:56
@HaBom Thank you for your info. I'm not sure if both posts are referring to the same problem. In my case, multiple cameras can work on my workstation of my HP laptop if I insert them directly to usb ports on my machines. But if I use a usb hub and then connect two cameras to the same external hub, then this problem occurs. I checked that under both circumstances, both cameras are connected to the same usb bus (using 'lsusb'), so I'm a bit confused what may have caused my problem, seems like the hub is limiting the performance?
– Wenbin Xu
Jan 7 at 1:47
@HaBom Thank you for your info. I'm not sure if both posts are referring to the same problem. In my case, multiple cameras can work on my workstation of my HP laptop if I insert them directly to usb ports on my machines. But if I use a usb hub and then connect two cameras to the same external hub, then this problem occurs. I checked that under both circumstances, both cameras are connected to the same usb bus (using 'lsusb'), so I'm a bit confused what may have caused my problem, seems like the hub is limiting the performance?
– Wenbin Xu
Jan 7 at 1:47
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54033926%2fcannot-capture-frames-from-two-cameras-through-one-hub-simultaneously-on-windo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54033926%2fcannot-capture-frames-from-two-cameras-through-one-hub-simultaneously-on-windo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@HaBom thank you for your reply. The second process break at line 'ret, frame = cap.read()', so it may not be caused by the name of the windows. And this code works fine on my ubuntu machine.
– Wenbin Xu
Jan 4 at 6:29
I just realise that it's not the problem. I don't have 2 usb cameras, so I try with ip cameras and videos also, but there's nothing wrong with the code. I think maybe it's a bandwidth problem as you've mentioned. I've found another post with the same problem as yours stackoverflow.com/questions/29664399/…
– Ha Bom
Jan 4 at 6:56
@HaBom Thank you for your info. I'm not sure if both posts are referring to the same problem. In my case, multiple cameras can work on my workstation of my HP laptop if I insert them directly to usb ports on my machines. But if I use a usb hub and then connect two cameras to the same external hub, then this problem occurs. I checked that under both circumstances, both cameras are connected to the same usb bus (using 'lsusb'), so I'm a bit confused what may have caused my problem, seems like the hub is limiting the performance?
– Wenbin Xu
Jan 7 at 1:47