|
Link Here
|
| 2235 |
|
2235 |
|
| 2236 |
void PencilTestPopup::onCameraListComboActivated(int comboIndex) { |
2236 |
void PencilTestPopup::onCameraListComboActivated(int comboIndex) { |
| 2237 |
QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); |
2237 |
QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); |
| 2238 |
if (cameras.size() != m_cameraListCombo->count() - 1) return; |
2238 |
if (cameras.size() != m_cameraListCombo->count() - 1 || comboIndex < 0 || |
|
|
2239 |
comboIndex > cameras.size()) |
| 2240 |
return; |
| 2241 |
// Reselecting the current camera must not stop its capture timer. |
| 2242 |
if (comboIndex > 0 && |
| 2243 |
cameras.at(comboIndex - 1).deviceName() == m_deviceName) |
| 2244 |
return; |
| 2239 |
|
2245 |
|
| 2240 |
m_cvWebcam.release(); |
2246 |
m_cvWebcam.release(); |
| 2241 |
if (m_timer->isActive()) m_timer->stop(); |
2247 |
if (m_timer->isActive()) m_timer->stop(); |
|
Link Here
|
| 2251 |
} |
2257 |
} |
| 2252 |
|
2258 |
|
| 2253 |
int index = comboIndex - 1; |
2259 |
int index = comboIndex - 1; |
| 2254 |
// In case the camera is not changed (just click the combobox) |
|
|
| 2255 |
if (cameras.at(index).deviceName() == m_deviceName) return; |
| 2256 |
|
| 2257 |
m_currentCamera = new QCamera(cameras.at(index), this); |
2260 |
m_currentCamera = new QCamera(cameras.at(index), this); |
| 2258 |
m_deviceName = cameras.at(index).deviceName(); |
2261 |
m_deviceName = cameras.at(index).deviceName(); |
| 2259 |
|
2262 |
|
|
Link Here
|
| 2263 |
// Refresh resolution |
2266 |
// Refresh resolution |
| 2264 |
m_resolutionCombo->clear(); |
2267 |
m_resolutionCombo->clear(); |
| 2265 |
QList<QSize> sizes = m_currentCamera->supportedViewfinderResolutions(); |
2268 |
QList<QSize> sizes = m_currentCamera->supportedViewfinderResolutions(); |
|
|
2269 |
bool resolutionsDetected = !sizes.isEmpty(); |
| 2266 |
// Simple workaround because Qt fails to auto-detect the camera resolutions |
2270 |
// Simple workaround because Qt fails to auto-detect the camera resolutions |
| 2267 |
// https://forum.qt.io/topic/68904/how-to-get-the-supported-resolution-of-a-qcamera/5 |
2271 |
// https://forum.qt.io/topic/68904/how-to-get-the-supported-resolution-of-a-qcamera/5 |
| 2268 |
if (sizes.size() == 0) { |
2272 |
if (sizes.size() == 0) { |
|
Link Here
|
| 2288 |
QString("%1 x %2").arg(size.width()).arg(size.height()), size); |
2292 |
QString("%1 x %2").arg(size.width()).arg(size.height()), size); |
| 2289 |
} |
2293 |
} |
| 2290 |
if (!sizes.isEmpty()) { |
2294 |
if (!sizes.isEmpty()) { |
| 2291 |
// Select the largest available resolution |
2295 |
// Do not default to an unverified 4K mode when Qt cannot query the camera. |
| 2292 |
m_resolutionCombo->setCurrentIndex(m_resolutionCombo->count() - 1); |
2296 |
m_resolutionCombo->setCurrentIndex( |
|
|
2297 |
resolutionsDetected ? m_resolutionCombo->count() - 1 |
| 2298 |
: m_resolutionCombo->findData(QSize(640, 480))); |
| 2293 |
} |
2299 |
} |
| 2294 |
|
2300 |
|
| 2295 |
m_videoWidget->setImage(QImage()); |
2301 |
m_videoWidget->setImage(QImage()); |
|
Link Here
|
| 2598 |
} else { |
2604 |
} else { |
| 2599 |
m_cvWebcam.open(camIndex, cv::CAP_DSHOW); |
2605 |
m_cvWebcam.open(camIndex, cv::CAP_DSHOW); |
| 2600 |
} |
2606 |
} |
|
|
2607 |
#elif defined(__linux__) |
| 2608 |
// Qt's camera ordinal need not match the /dev/videoN device number. |
| 2609 |
m_cvWebcam.open(m_deviceName.toStdString(), cv::CAP_V4L2); |
| 2601 |
#else |
2610 |
#else |
| 2602 |
m_cvWebcam.open(translateIndex(camIndex)); |
2611 |
m_cvWebcam.open(translateIndex(camIndex)); |
| 2603 |
#endif |
2612 |
#endif |