Skip to content

fix: AVFoundation inconsistent camera indices#22946

Merged
asmorkalov merged 1 commit intoopencv:3.4from
VadimLevin:dev/vlevin/avfoundation-stable-multicamera-index
Dec 13, 2022
Merged

fix: AVFoundation inconsistent camera indices#22946
asmorkalov merged 1 commit intoopencv:3.4from
VadimLevin:dev/vlevin/avfoundation-stable-multicamera-index

Conversation

@VadimLevin
Copy link
Copy Markdown
Contributor

Resolves #22901

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@asmorkalov
Copy link
Copy Markdown
Contributor

@calism2 Could you test it with your setup?

@calism2
Copy link
Copy Markdown

calism2 commented Dec 12, 2022

I tested ( Apple M1 Max - Ventura - OpenCv 4.x ) but result same. It seems sort doesn't work as expected.

Changes

modules/videoio/src/cap_avfoundation_mac.mm

    fprintf(stdout, "\nOpenCV: device id %d.\n", cameraNum);
    devices = [devices sortedArrayUsingSelector: @selector(uniqueID)];
    for( int i=0; i < devices.count; i++  ){
        mCaptureDevice = devices[i];
        NSLog(@"OpenCV uniqueID id: %@", mCaptureDevice.uniqueID);
    }
    fprintf(stdout, "%s", "----------------------------\n");
    mCaptureDevice = devices[cameraNum];

Run log (2 Camera)

% make && ./CalibrationCollectData
[100%] Built target CalibrationCollectData

OpenCV: device id 0.
2022-12-12 15:52:11.279 CalibrationCollectData[80237:2407690] OpenCV uniqueID id: 0x514000015bc0000
2022-12-12 15:52:11.279 CalibrationCollectData[80237:2407690] OpenCV uniqueID id: 0x414000015bc0000
----------------------------

OpenCV: device id 1.
2022-12-12 15:52:11.895 CalibrationCollectData[80237:2407690] OpenCV uniqueID id: 0x414000015bc0000
2022-12-12 15:52:11.895 CalibrationCollectData[80237:2407690] OpenCV uniqueID id: 0x514000015bc0000

Run log (4 Camera)

% make && ./CalibrationCollectData
[100%] Built target CalibrationCollectData

OpenCV: device id 0.
2022-12-12 15:55:18.120 CalibrationCollectData[80265:2409339] OpenCV uniqueID id: 0x83430001bcf2286
2022-12-12 15:55:18.120 CalibrationCollectData[80265:2409339] OpenCV uniqueID id: 0x83440000edc2076
2022-12-12 15:55:18.120 CalibrationCollectData[80265:2409339] OpenCV uniqueID id: 0x414000015bc0000
2022-12-12 15:55:18.120 CalibrationCollectData[80265:2409339] OpenCV uniqueID id: 0x514000015bc0000
----------------------------

OpenCV: device id 1.
2022-12-12 15:55:18.567 CalibrationCollectData[80265:2409339] OpenCV uniqueID id: 0x83440000edc2076
2022-12-12 15:55:18.567 CalibrationCollectData[80265:2409339] OpenCV uniqueID id: 0x414000015bc0000
2022-12-12 15:55:18.567 CalibrationCollectData[80265:2409339] OpenCV uniqueID id: 0x514000015bc0000
2022-12-12 15:55:18.567 CalibrationCollectData[80265:2409339] OpenCV uniqueID id: 0x83430001bcf2286

@VadimLevin VadimLevin force-pushed the dev/vlevin/avfoundation-stable-multicamera-index branch from be68bcd to 727feda Compare December 12, 2022 14:17
@VadimLevin
Copy link
Copy Markdown
Contributor Author

VadimLevin commented Dec 12, 2022

My bad, I misused sorting function it should use comparator instead of selector.

@calism2 can you recheck please?

@asmorkalov asmorkalov added this to the 3.4.19 milestone Dec 12, 2022
@calism2
Copy link
Copy Markdown

calism2 commented Dec 12, 2022

@VadimLevin Works perfectly. Thank you.

@asmorkalov asmorkalov self-requested a review December 12, 2022 14:59
@asmorkalov asmorkalov self-assigned this Dec 12, 2022
@asmorkalov asmorkalov merged commit c2ecbc7 into opencv:3.4 Dec 13, 2022
@alalek alalek mentioned this pull request Dec 18, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
@asmorkalov asmorkalov mentioned this pull request Jan 10, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants