tahoma2d/toonz/sources/stopmotion/webcam.h

123 lines
3.2 KiB
C
Raw Normal View History

2020-04-27 16:15:39 +12:00
#pragma once
#ifndef WEBCAM_H
#define WEBCAM_H
#include "opencv2/opencv.hpp"
// Toonz Includes
#include "traster.h"
#include "toonzqt/gutil.h"
#include <QObject>
class QCamera;
class QCameraInfo;
2020-04-27 16:19:06 +12:00
class Webcam : public QObject {
Q_OBJECT
2020-04-27 16:15:39 +12:00
public:
2020-04-27 16:19:06 +12:00
Webcam();
~Webcam();
2020-04-27 16:15:39 +12:00
2020-04-27 16:19:06 +12:00
void setWebcamDeviceName(QString name) { m_webcamDeviceName = name; }
QString getWebcamDeviceName() { return m_webcamDeviceName; }
2020-04-27 16:15:39 +12:00
2020-04-27 16:19:06 +12:00
void setWebcamDescription(QString desc) { m_webcamDescription = desc; }
QString getWebcamDescription() { return m_webcamDescription; }
2020-04-27 16:15:39 +12:00
2020-04-27 16:19:06 +12:00
void setWebcamIndex(int index) { m_webcamIndex = index; }
int getWebcamIndex() { return m_webcamIndex; }
2020-04-27 16:15:39 +12:00
2020-04-27 16:19:06 +12:00
int getWebcamWidth() { return m_webcamWidth; }
int getWebcamHeight() { return m_webcamHeight; }
void setWebcamWidth(int width) { m_webcamWidth = width; }
void setWebcamHeight(int height) { m_webcamHeight = height; }
void releaseWebcam();
2020-04-27 16:15:39 +12:00
void clearWebcam();
QList<QCameraInfo> getWebcams();
QCamera* getWebcam() { return m_webcam; }
void setWebcam(QCamera* camera);
bool initWebcam(int index = 0);
2020-04-27 16:19:06 +12:00
bool getWebcamImage(TRaster32P& tempImage);
2020-04-27 16:15:39 +12:00
bool translateIndex(int index);
2020-04-27 16:19:06 +12:00
2020-04-27 16:15:39 +12:00
QList<QSize> getWebcamResolutions() { return m_webcamResolutions; }
int getIndexOfResolution();
void clearWebcamResolutions();
void refreshWebcamResolutions();
2020-04-27 16:19:06 +12:00
2020-04-27 16:15:39 +12:00
void setUseMjpg(bool on);
bool getUseMjpg() { return m_useMjpg; }
bool getUseDirectShow() { return m_useDirectShow; }
void setUseDirectShow(int state);
2020-04-28 17:02:21 +12:00
bool getWebcamAutofocusStatus();
void setWebcamAutofocusStatus(bool on);
int getWebcamFocusValue();
void setWebcamFocusValue(int value);
int getWebcamExposureValue();
void setWebcamExposureValue(int value);
int getWebcamBrightnessValue();
void setWebcamBrightnessValue(int value);
int getWebcamContrastValue();
void setWebcamContrastValue(int value);
int getWebcamGainValue();
void setWebcamGainValue(int value);
int getWebcamSaturationValue();
void setWebcamSaturationValue(int value);
void openSettingsWindow();
void setLut(cv::Mat lut) { m_lut = lut; }
void setColorMode(int mode) { m_colorMode = mode; }
void setWhite(int white) { m_white = white; }
void setBlack(int black) { m_black = black; }
void setThreshold(int threshold) { m_threshold = threshold; }
void setGamma(double gamma) { m_gamma = gamma; }
void computeLut();
cv::Mat getWebcamImage() { return m_webcamImage; }
2020-04-28 17:02:21 +12:00
2020-04-27 16:15:39 +12:00
private:
// Webcam Properties
QList<QCameraInfo> m_webcams;
QCamera* m_webcam;
cv::VideoCapture m_cvWebcam;
QList<QSize> m_webcamResolutions;
// Webcam Public Properties
QString m_webcamDeviceName;
QString m_webcamDescription;
2020-04-27 16:19:06 +12:00
int m_webcamIndex = -1;
2020-04-27 16:15:39 +12:00
bool m_useDirectShow = true;
2020-04-27 16:19:06 +12:00
int m_webcamWidth = 0;
int m_webcamHeight = 0;
bool m_useMjpg = true;
int m_colorMode = 0;
int m_white = 255;
int m_black = 0;
int m_threshold = 128;
double m_gamma = 1.0;
cv::Mat m_lut;
cv::Mat m_webcamImage;
2020-04-27 16:15:39 +12:00
2020-04-28 17:02:21 +12:00
int m_webcamFocusValue = 0;
bool m_webcamAutofocusStatus = true;
void adjustLevel(cv::Mat& image);
void binarize(cv::Mat& image);
2020-04-27 16:15:39 +12:00
signals:
2020-04-27 16:19:06 +12:00
void useMjpgSignal(bool);
void useDirectShowSignal(bool);
void updateHistogram(cv::Mat);
2020-04-27 16:15:39 +12:00
};
#endif // WEBCAM_H