Repository: opencv
Issue: crash when using CvVideoCamera
Labels: bug

### System Information

System information (version)

OpenCV => 4.1.0
Operating System / Platform => iOS 16.6.1
Device => iPhone 7 / iPhone 7 Plus
Compiler => Xcode Version 15.0


### Detailed description


I found a crash in my app when start video capture by using CvVideoCamera, and I confirmed that already granted to use the camera. Crash log above.

After a series of troubleshooting and reading the OpenCV source code, I discovered that the crash might occur at the locations marked by the red circles in the screenshot, where either self.captureSession.inputs or device.activeFormat.videoSupportedFrameRateRanges is nil. That maybe issue.

I wanted to ask, in what situations would the above two be nil? I can't reproduce this problem on a normal iPhone. Could it be due to a damaged camera or some restrictions from the user?"


```
CrashDoctor Diagnosis: Application threw exception NSRangeException: *** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray
Originated at or in a subcall of tflite::optimize::sparsity::FormatConverter<Eigen::half>::SparseToDense(Eigen::half const*, unsigned long, Eigen::half*, TfLiteContext*)
Thread 0 Crashed:
0   CoreFoundation                      0x000000018143bc60 0x1813a9000 + 601184
1   libobjc.A.dylib                     0x0000000198c67ee4 0x198c53000 + 85732
2   CoreFoundation                      0x00000001814bcb30 0x1813a9000 + 1129264
3   oasis                               0x00000001062c3d60 -[CvVideoCamera createVideoDataOutput] + [ : 456] 
4   oasis                               0x00000001062c4410 -[CvVideoCamera createCaptureOutput] + [ : 28] 
5   oasis                               0x00000001062c2420 -[CvAbstractCamera startCaptureSession] + [ : 100] 
6   oasis                               0x00000001062c3400 -[CvVideoCamera start] + [ : 88] 
7   oasis                               0x0000000104bc4fc8 -[MCDetectManager startCamera] + [MCDetectManager.mm : 239] 
8   oasis                               0x0000000104bc4cb0 -[MCDetectManager setupDetect:] + [MCDetectManager.mm : 194] 
9   oasis                               0x0000000104a929cc -[UnityManager startDetect] + [UnityManager.m : 0] 
10  UnityFramework                      0x000000010d655dbc 0x10b4c4000 + 35200444
11  UnityFramework                      0x000000010d636120 0x10b4c4000 + 35070240
12  UnityFramework                      0x000000010b627fe0 0x10b4c4000 + 1458144
13  UnityFramework                      0x000000010c53a7c0 0x10b4c4000 + 17262528
14  UnityFramework                      0x000000010c53a584 0x10b4c4000 + 17261956
15  UnityFramework                      0x000000010c53aad4 0x10b4c4000 + 17263316
16  UnityFramework                      0x000000010c4e2e84 0x10b4c4000 + 16903812
17  UnityFramework                      0x000000010e29ad1c 0x10b4c4000 + 48065820
18  UnityFramework                      0x000000010d39db80 0x10b4c4000 + 32349056
19  UnityFramework                      0x000000010d30bbe4 0x10b4c4000 + 31751140
20  UnityFramework                      0x000000010d311c64 0x10b4c4000 + 31775844
21  UnityFramework                      0x000000010d311c64 0x10b4c4000 + 31775844
22  UnityFramework                      0x000000010d3380ec 0x10b4c4000 + 31932652
23  UnityFramework                      0x000000010d3374e8 0x10b4c4000 + 31929576
24  UnityFramework                      0x000000010d337400 0x10b4c4000 + 31929344
25  UnityFramework                      0x000000010dff829c 0x10b4c4000 + 45302428
26  UnityFramework                      0x000000010c791298 0x10b4c4000 + 19714712
27  UnityFramework                      0x000000010e0b94c8 0x10b4c4000 + 46093512
28  UnityFramework                      0x000000010e0b8aac 0x10b4c4000 + 46090924
29  UnityFramework                      0x000000010e0b87ec 0x10b4c4000 + 46090220
30  UnityFramework                      0x000000010c53a73c 0x10b4c4000 + 17262396
31  UnityFramework                      0x000000010c53a584 0x10b4c4000 + 17261956
32  UnityFramework                      0x000000010ba23ef0 0x10b4c4000 + 5635824
33  UnityFramework                      0x000000010ba2fc74 0x10b4c4000 + 5684340
34  UnityFramework                      0x000000010ba3f3f0 0x10b4c4000 + 5747696
35  UnityFramework                      0x000000010b88628c 0x10b4c4000 + 3941004
36  UnityFramework                      0x000000010b94859c 0x10b4c4000 + 4736412
37  UnityFramework                      0x000000010b9485dc 0x10b4c4000 + 4736476
38  UnityFramework                      0x000000010b948838 0x10b4c4000 + 4737080
39  UnityFramework                      0x000000010bfaaee8 0x10b4c4000 + 11431656
40  UnityFramework                      0x000000010b4d9ed4 0x10b4c4000 + 89812
41  UnityFramework                      0x000000010b4d9e4c 0x10b4c4000 + 89676
42  QuartzCore                          0x0000000184eb2cec 0x184ea3000 + 64748
43  QuartzCore                          0x0000000184eb9880 0x184ea3000 + 92288
44  CoreFoundation                      0x00000001813b39fc 0x1813a9000 + 43516
45  CoreFoundation                      0x00000001813f3c6c 0x1813a9000 + 306284
46  CoreFoundation                      0x00000001813f7270 0x1813a9000 + 320112
47  CoreFoundation                      0x00000001813b4460 0x1813a9000 + 46176
48  CoreFoundation                      0x00000001813c7174 0x1813a9000 + 123252
49  GraphicsServices                    0x00000001a1f06988 0x1a1f05000 + 6536
50  UIKitCore                           0x0000000183bc9a88 0x1836e4000 + 5134984
51  UIKitCore                           0x0000000183962f78 0x1836e4000 + 2617208
52  oasis                               0x0000000104ceb0f0 main + [main.m : 18] 
53  (null) 0x00000001077a84d0 0x0 + 4420437200
Thread 1 name:  com.apple.uikit.eventfetch-thread
Thread 1:
0   libsystem_kernel.dylib              0x00000001bbd19aac 0x1bbd19000 + 2732
1   libsystem_kernel.dylib              0x00000001bbd1a07c 0x1bbd19000 + 4220
2   CoreFoundation                      0x00000001813afc88 0x1813a9000 + 27784
3   CoreFoundation                      0x00000001813b3f90 0x1813a9000 + 44944
4   CoreFoundation                      0x00000001813c7174 0x1813a9000 + 123252
5   Foundation                          0x0000000182ad3eac 0x182abc000 + 97964
6   Foundation                          0x0000000182b12fd0 0x182abc000 + 356304
7   UIKitCore                           0x0000000183b48ef4 0x1836e4000 + 4607732
8   Foundation                          0x0000000182b20bdc 0x182abc000 + 412636
9   libsystem_pthread.dylib             0x00000001dc7b6338 0x1dc7b3000 + 13112

```

### Steps to reproduce


Sourcecode screenshot in latest file "cap_ios_video_camera.mm"

<img width="1335" alt="image" src="https://github.com/opencv/opencv/assets/15337294/d29dad49-d9a3-43b0-9bcc-81fced06ee17">



### Issue submission checklist

- [X] I report the issue, it's not a question
- [X] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [ ] I updated to the latest OpenCV version and the issue is still there
- [ ] There is reproducer code and related data files (videos, images, onnx, etc)