OpenToonz - An open-source full-featured 2D animation creation software
C
camera capture: save default image adjust parameters
shun-iwasawaad519f97ba27
diff --git a/toonz/sources/toonz/cameracapturelevelcontrol.cpp b/toonz/sources/toonz/cameracapturelevelcontrol.cppindex 3714154a3..b9746fd13 100644--- a/toonz/sources/toonz/cameracapturelevelcontrol.cpp+++ b/toonz/sources/toonz/cameracapturelevelcontrol.cpp@@ -399,4 +399,35 @@ void CameraCaptureLevelControl::computeLut() {p[i] = (uchar)std::floor(value * maxChannelValueF);}+}++//-----------------------------------------------------------------------------++void CameraCaptureLevelControl::getValues(int& black, int& white,+ int& threshold, double& gamma) {+ black = m_histogram->black();+ white = m_histogram->white();+ threshold = m_histogram->threshold();+ gamma = (double)m_histogram->gamma();+}++//-----------------------------------------------------------------------------++void CameraCaptureLevelControl::setValues(const int black, const int white,+ const int threshold,+ const double gamma,+ const bool color_grayscale) {+ m_whiteFld->setRange(black + 2, 255);+ m_blackFld->setRange(0, white - 2);+ m_blackFld->setValue(black);+ m_whiteFld->setValue(white);+ m_gammaFld->setValue(gamma);+ m_thresholdFld->setValue(threshold);++ m_histogram->setValues(m_blackFld->getValue(), m_whiteFld->getValue(),+ m_gammaFld->getValue());+ m_histogram->setThreshold(m_thresholdFld->getValue());++ setMode(color_grayscale);+ computeLut();}\ No newline at end of filediff --git a/toonz/sources/toonz/cameracapturelevelcontrol.h b/toonz/sources/toonz/cameracapturelevelcontrol.hindex 5e3c1917e..f89031a19 100644--- a/toonz/sources/toonz/cameracapturelevelcontrol.h+++ b/toonz/sources/toonz/cameracapturelevelcontrol.h@@ -89,6 +89,11 @@ public:void adjustLevel(cv::Mat& image);void binarize(cv::Mat& image);+ // for saving / loading default+ void getValues(int& black, int& white, int& threshold, double& gamma);+ void setValues(const int black, const int white, const int threshold,+ const double gamma, const bool color_grayscale);+protected slots:void onHistogramValueChanged(int itemId);void onFieldChanged();diff --git a/toonz/sources/toonz/icons/dark/actions/16/gear_check.svg b/toonz/sources/toonz/icons/dark/actions/16/gear_check.svgnew file mode 100644index 000000000..885734bc4--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16/gear_check.svg@@ -0,0 +1,56 @@+<?xml version="1.0" encoding="UTF-8" standalone="no"?>+<svg+ width="16px"+ height="16px"+ version="1.1"+ xml:space="preserve"+ style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"+ id="svg698"+ sodipodi:docname="gear_check.svg"+ inkscape:version="1.2.1 (9c6d41e410, 2022-07-14)"+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"+ xmlns="http://www.w3.org/2000/svg"+ xmlns:svg="http://www.w3.org/2000/svg"><defs+ id="defs702" /><sodipodi:namedview+ id="namedview700"+ pagecolor="#ffffff"+ bordercolor="#000000"+ borderopacity="0.25"+ inkscape:showpageshadow="2"+ inkscape:pageopacity="0.0"+ inkscape:pagecheckerboard="0"+ inkscape:deskcolor="#d1d1d1"+ showgrid="false"+ inkscape:zoom="45.387417"+ inkscape:cx="9.088422"+ inkscape:cy="7.7113884"+ inkscape:window-width="2560"+ inkscape:window-height="1377"+ inkscape:window-x="-8"+ inkscape:window-y="-8"+ inkscape:window-maximized="1"+ inkscape:current-layer="svg698" />+ <g+ transform="matrix(1,0,0,1,-2,-2)"+ id="g692">+ <rect+ x="0"+ y="0"+ width="20"+ height="20"+ style="fill-opacity:0;"+ id="rect690" />+ </g>+ <g+ transform="matrix(1,0,0,1,-314,-42.0002)"+ id="g696">+ <path+ id="path694"+ d="M 322 43.0002 C 321.63375 43.0002 321.2668 43.028638 320.9043 43.086137 C 320.6983 43.689137 320.58822 44.310466 320.57422 44.947466 C 320.17722 45.059466 319.79555 45.217169 319.43555 45.418169 C 318.97455 44.978169 318.45872 44.617137 317.88672 44.336137 C 317.29172 44.768137 316.76989 45.291919 316.33789 45.886919 C 316.61889 46.458918 316.97992 46.974747 317.41992 47.435747 C 317.21892 47.795747 317.05927 48.177419 316.94727 48.574419 C 316.31027 48.588419 315.68894 48.698497 315.08594 48.904497 C 314.97094 49.629496 314.97094 50.370904 315.08594 51.095903 C 315.68894 51.301903 316.31027 51.410028 316.94727 51.424028 C 317.05927 51.821028 317.21892 52.204653 317.41992 52.564653 C 316.97992 53.025653 316.61889 53.541482 316.33789 54.113481 C 316.76989 54.708481 317.29172 55.23031 317.88672 55.662309 C 318.45872 55.38131 318.97455 55.020278 319.43555 54.580278 C 319.79555 54.781278 320.17722 54.940934 320.57422 55.052934 C 320.58822 55.689934 320.6983 56.311263 320.9043 56.914262 C 321.6293 57.029262 322.3707 57.029262 323.0957 56.914262 C 323.3017 56.311263 323.41178 55.689934 323.42578 55.052934 C 323.82278 54.940934 324.20445 54.781278 324.56445 54.580278 C 325.02545 55.020278 325.54128 55.38131 326.11328 55.662309 C 326.70828 55.23031 327.23011 54.708481 327.66211 54.113481 C 327.38111 53.541482 327.02008 53.025653 326.58008 52.564653 C 326.78108 52.204653 326.94073 51.821028 327.05273 51.424028 C 327.68973 51.410028 328.31106 51.301903 328.91406 51.095903 C 329.02906 50.370904 329.02906 49.629496 328.91406 48.904497 C 328.31106 48.698497 327.68973 48.588419 327.05273 48.574419 C 326.94073 48.177419 326.78108 47.795747 326.58008 47.435747 C 327.02008 46.974747 327.38111 46.458918 327.66211 45.886919 C 327.23011 45.291919 326.70828 44.768137 326.11328 44.336137 C 325.54128 44.617137 325.02545 44.978169 324.56445 45.418169 C 324.20445 45.217169 323.82278 45.059466 323.42578 44.947466 C 323.41178 44.310466 323.3017 43.689137 323.0957 43.086137 C 322.7332 43.028638 322.36625 43.0002 322 43.0002 z M 322 46.074419 A 3.9262602 3.9262602 0 0 1 325.92578 50.0002 A 3.9262602 3.9262602 0 0 1 322 53.925981 A 3.9262602 3.9262602 0 0 1 318.07422 50.0002 A 3.9262602 3.9262602 0 0 1 322 46.074419 z " />+ </g>+<path+ d="M 6.2228883,7.0365135 7.5149871,8.2801072 9.6224346,6.1458198 C 9.7917107,5.9742561 9.8969365,5.8358614 10.106244,6.0508879 l 0.675961,0.6919731 c 0.223032,0.2196017 0.210451,0.3477027 0.0011,0.5512923 L 7.9015784,10.130708 c -0.4414906,0.432341 -0.363715,0.458647 -0.8120681,0.01487 L 5.0848502,8.1528185 C 4.9922058,8.0521673 5.001356,7.950373 5.1031504,7.8485786 L 5.8877683,7.0342228 c 0.1178071,-0.1223817 0.212739,-0.1143761 0.3351211,0.00227 z"+ style="clip-rule:evenodd;fill-rule:evenodd;stroke-width:1"+ id="path2565"+ sodipodi:nodetypes="ccccccccccccc" /></svg>diff --git a/toonz/sources/toonz/penciltestpopup.cpp b/toonz/sources/toonz/penciltestpopup.cppindex 84e6a94bf..a96098e64 100644--- a/toonz/sources/toonz/penciltestpopup.cpp+++ b/toonz/sources/toonz/penciltestpopup.cpp@@ -124,6 +124,7 @@ TEnv::IntVar CamCapDoCalibration("CamCapDoCalibration", 0);TEnv::RectVar CamCapSubCameraRect("CamCapSubCameraRect", TRect());TEnv::IntVar CamCapDoAutoDpi("CamCapDoAutoDpi", 1);TEnv::DoubleVar CamCapCustomDpi("CamCapDpiForNewLevel", 120.0);+TEnv::StringVar CamCapFileType("CamCapFileType", "jpg");namespace {@@ -433,6 +434,38 @@ protected:}};+// https://stackoverflow.com/a/50848100/6622587+cv::Mat QImageToMat(const QImage& image) {+ cv::Mat out;+ switch (image.format()) {+ case QImage::Format_Invalid: {+ cv::Mat empty;+ empty.copyTo(out);+ break;+ }+ case QImage::Format_RGB32: {+ cv::Mat view(image.height(), image.width(), CV_8UC4,+ (void*)image.constBits(), image.bytesPerLine());+ view.copyTo(out);+ break;+ }+ case QImage::Format_RGB888: {+ cv::Mat view(image.height(), image.width(), CV_8UC3,+ (void*)image.constBits(), image.bytesPerLine());+ cv::cvtColor(view, out, cv::COLOR_RGB2BGR);+ break;+ }+ default: {+ QImage conv = image.convertToFormat(QImage::Format_ARGB32);+ cv::Mat view(conv.height(), conv.width(), CV_8UC4, (void*)conv.constBits(),+ conv.bytesPerLine());+ view.copyTo(out);+ break;+ }+ }+ return out;+}+} // namespace//=============================================================================@@ -1556,8 +1589,9 @@ PencilTestPopup::PencilTestPopup()m_saveOnCaptureCB =new QCheckBox(tr("Save images as they are captured"), this);- QGroupBox* imageFrame = new QGroupBox(tr("Image adjust"), this);- m_colorTypeCombo = new QComboBox(this);+ QGroupBox* imageFrame = new QGroupBox(tr("Image adjust"), this);+ m_colorTypeCombo = new QComboBox(this);+ m_saveImgAdjustDefaultButton = new QPushButton(this);m_camCapLevelControl = new CameraCaptureLevelControl(this);m_upsideDownCB = new QCheckBox(tr("Upside down"), this);@@ -1610,7 +1644,7 @@ PencilTestPopup::PencilTestPopup()m_resolutionCombo->setMaximumWidth(fontMetrics().width("0000 x 0000") + 25);m_fileTypeCombo->addItems({"jpg", "png", "tga", "tif"});- m_fileTypeCombo->setCurrentIndex(0);+ m_fileTypeCombo->setCurrentText(QString::fromStdString(CamCapFileType));fileFrame->setObjectName("CleanupSettingsFrame");m_frameNumberEdit->setObjectName("LargeSizedText");@@ -1627,6 +1661,11 @@ PencilTestPopup::PencilTestPopup()m_colorTypeCombo->addItems({tr("Color"), tr("Grayscale"), tr("Black & White")});m_colorTypeCombo->setCurrentIndex(0);+ m_saveImgAdjustDefaultButton->setFixedSize(24, 24);+ m_saveImgAdjustDefaultButton->setIconSize(QSize(16, 16));+ m_saveImgAdjustDefaultButton->setIcon(createQIcon("gear_check"));+ m_saveImgAdjustDefaultButton->setToolTip(+ tr("Save Current Image Adjust Parameters As Default"));m_upsideDownCB->setChecked(false);m_bgReductionFld->setRange(0, 100);@@ -1824,6 +1863,8 @@ PencilTestPopup::PencilTestPopup()imageLay->addWidget(new QLabel(tr("Color type:"), this), 0, 0,Qt::AlignRight);imageLay->addWidget(m_colorTypeCombo, 0, 1);+ imageLay->addWidget(m_saveImgAdjustDefaultButton, 0, 2,+ Qt::AlignRight);imageLay->addWidget(m_camCapLevelControl, 1, 0, 1, 3);@@ -1918,6 +1959,8 @@ PencilTestPopup::PencilTestPopup()SLOT(onPreviousName()));ret = ret && connect(m_colorTypeCombo, SIGNAL(currentIndexChanged(int)), this,SLOT(onColorTypeComboChanged(int)));+ ret = ret && connect(m_saveImgAdjustDefaultButton, SIGNAL(pressed()), this,+ SLOT(saveImageAdjustDefault()));ret = ret && connect(m_captureWhiteBGButton, SIGNAL(pressed()), this,SLOT(onCaptureWhiteBGButtonPressed()));ret = ret && connect(m_onionSkinGBox, SIGNAL(toggled(bool)), this,@@ -1942,8 +1985,12 @@ PencilTestPopup::PencilTestPopup()SLOT(openSaveInFolderPopup()));ret = ret && connect(m_saveInFileFld, SIGNAL(pathChanged()), this,SLOT(onSaveInPathEdited()));- ret = ret && connect(m_fileTypeCombo, SIGNAL(activated(int)), this,- SLOT(refreshFrameInfo()));+ ret = ret &&+ connect(m_fileTypeCombo, QOverload<int>::of(&QComboBox::activated),+ [&](int index) {+ CamCapFileType = m_fileTypeCombo->currentText().toStdString();+ refreshFrameInfo();+ });ret = ret && connect(m_frameNumberEdit, SIGNAL(editingFinished()), this,SLOT(refreshFrameInfo()));@@ -2040,6 +2087,9 @@ PencilTestPopup::PencilTestPopup()m_videoWidget->setImage(dummyImg);m_subcameraButton->setChecked(true);}++ // try loading the default parameter+ loadImageAdjustDefault();}}@@ -3466,6 +3516,13 @@ void PencilTestPopup::onSaveInPathEdited() {//-----------------------------------------------------------------------------+void PencilTestPopup::onFileTypeChanged() {+ CamCapFileType = m_fileTypeCombo->currentText().toStdString();+ refreshFrameInfo();+}++//-----------------------------------------------------------------------------+void PencilTestPopup::onSceneSwitched() {m_saveInFolderPopup->updateParentFolder();m_saveInFileFld->setPath(m_saveInFolderPopup->getParentPath());@@ -3616,14 +3673,33 @@ void PencilTestPopup::resetCalibSettingsFromFile() {//------------------------------------------------------------------------------QString PencilTestPopup::getCurrentCalibFilePath() {+QString PencilTestPopup::getCameraConfigurationPath(const QString& folderName,+ const QString& ext) {QString cameraName = m_cameraListCombo->currentText();if (cameraName.isEmpty()) return QString();QString resolution = m_resolutionCombo->currentText();QString hostName = QHostInfo::localHostName();- TFilePath folderPath = ToonzFolder::getLibraryFolder() + "camera calibration";- return folderPath.getQString() + "\\" + hostName + "_" + cameraName + "_" +- resolution + ".xml";+ TFilePath folderPath = ToonzFolder::getLibraryFolder();+ return folderPath.getQString() + "\\" + folderName + "\\" + hostName + "_" ++ cameraName + "_" + resolution + "." + ext;+}++//-----------------------------------------------------------------------------++QString PencilTestPopup::getCurrentCalibFilePath() {+ return getCameraConfigurationPath("camera calibration", "xml");+}++//-----------------------------------------------------------------------------++QString PencilTestPopup::getImageAdjustSettingsPath() {+ return getCameraConfigurationPath("camera image adjust", "ini");+}++//-----------------------------------------------------------------------------++QString PencilTestPopup::getImageAdjustBgImgPath() {+ return getCameraConfigurationPath("camera image adjust", "jpg");}//-----------------------------------------------------------------------------@@ -3788,6 +3864,80 @@ void PencilTestPopup::onPreferenceChanged(const QString& prefName) {m_dpiBtn->setHidden(Preferences::instance()->getPixelsOnly());}+//-----------------------------------------------------------------------------+// called in ctor+void PencilTestPopup::loadImageAdjustDefault() {+ // find the configuration file+ QString settingsPath = getImageAdjustSettingsPath();+ if (!TFileStatus(TFilePath(settingsPath)).doesExist()) return;++ QSettings imgAdjSettings(settingsPath, QSettings::IniFormat);+ int colorType = imgAdjSettings.value("ColorType", 0).toInt();+ int black = imgAdjSettings.value("BlackLevel", 0).toInt();+ int white = imgAdjSettings.value("WhiteLevel", 255).toInt();+ double gamma = imgAdjSettings.value("Gamma", 1.0).toDouble();+ int threshold = imgAdjSettings.value("Threshold", 128).toInt();+ bool upsideDown = imgAdjSettings.value("UpsideDown", false).toBool();+ int bgReduction = imgAdjSettings.value("BgReduction", 0).toInt();++ m_colorTypeCombo->setCurrentIndex(colorType);+ m_camCapLevelControl->setValues(black, white, threshold, gamma,+ colorType != 2);+ m_upsideDownCB->setChecked(upsideDown);+ m_bgReductionFld->setValue(bgReduction);++ QString bgPath = getImageAdjustBgImgPath();+ if (!TFileStatus(TFilePath(bgPath)).doesExist()) {+ if (bgReduction > 0)+ warning(+ tr("BG Reduction is set but the White BG image is missing. Please "+ "capture the White BG again."));++ m_whiteBGImg = cv::Mat();+ m_bgReductionFld->setDisabled(true);+ return;+ }++ QImage bgImg(bgPath);+ if (bgImg.isNull()) {+ m_whiteBGImg = cv::Mat();+ m_bgReductionFld->setDisabled(true);+ return;+ }+ cv::Mat tmpMat = QImageToMat(bgImg);+ cv::cvtColor(tmpMat, m_whiteBGImg, cv::COLOR_RGBA2RGB);+ m_bgReductionFld->setEnabled(true);+}++//-----------------------------------------------------------------------------++void PencilTestPopup::saveImageAdjustDefault() {+ QString question =+ tr("Do you want to save the current parameters as the default values?");+ int ret = DVGui::MsgBox(question, QObject::tr("Save"), QObject::tr("Cancel"));+ if (ret == 0 || ret == 2) return;++ QString settingsPath = getImageAdjustSettingsPath();+ QSettings imgAdjSettings(settingsPath, QSettings::IniFormat);++ imgAdjSettings.setValue("ColorType", m_colorTypeCombo->currentIndex());+ int black, white, threshold;+ double gamma;+ m_camCapLevelControl->getValues(black, white, threshold, gamma);+ imgAdjSettings.setValue("BlackLevel", black);+ imgAdjSettings.setValue("WhiteLevel", white);+ imgAdjSettings.setValue("Gamma", gamma);+ imgAdjSettings.setValue("Threshold", threshold);+ imgAdjSettings.setValue("UpsideDown", m_upsideDownCB->isChecked());+ imgAdjSettings.setValue("BgReduction", m_bgReductionFld->getValue());++ if (!m_whiteBGImg.empty()) {+ QImage qimg(m_whiteBGImg.data, m_whiteBGImg.cols, m_whiteBGImg.rows,+ QImage::Format_RGB888);+ qimg.save(getImageAdjustBgImgPath());+ }+}+//-----------------------------------------------------------------------------OpenPopupCommandHandler<PencilTestPopup> openPencilTestPopup(MI_PencilTest);diff --git a/toonz/sources/toonz/penciltestpopup.h b/toonz/sources/toonz/penciltestpopup.hindex 60fe14002..397cb97a4 100644--- a/toonz/sources/toonz/penciltestpopup.h+++ b/toonz/sources/toonz/penciltestpopup.h@@ -271,7 +271,7 @@ class PencilTestPopup : public DVGui::Dialog {QCheckBox *m_upsideDownCB, *m_saveOnCaptureCB;QGroupBox *m_onionSkinGBox, *m_timerGBox;QPushButton *m_fileFormatOptionButton, *m_captureWhiteBGButton,- *m_captureButton, *m_loadImageButton;+ *m_captureButton, *m_loadImageButton, *m_saveImgAdjustDefaultButton;DVGui::FileField* m_saveInFileFld;FrameNumberLineEdit* m_frameNumberEdit;DVGui::IntField *m_bgReductionFld, *m_onionOpacityFld, *m_timerIntervalFld;@@ -341,8 +341,13 @@ class PencilTestPopup : public DVGui::Dialog {QMenu* createOptionsMenu();int translateIndex(int camIndex);+ void loadImageAdjustDefault();QString getCurrentCalibFilePath();+ QString getImageAdjustSettingsPath();+ QString getImageAdjustBgImgPath();+ QString getCameraConfigurationPath(const QString& folderName,+ const QString& ext);QWidget* createDpiMenuWidget();@@ -381,6 +386,7 @@ protected slots:void refreshFrameInfo();void onSaveInPathEdited();+ void onFileTypeChanged();void onSceneSwitched();void onSubCameraToggled(bool);@@ -398,6 +404,8 @@ protected slots:void onCalibReadme();void onPreferenceChanged(const QString&);+ void saveImageAdjustDefault();+public slots:void openSaveInFolderPopup();};diff --git a/toonz/sources/toonz/toonz.qrc b/toonz/sources/toonz/toonz.qrcindex 708740e0a..3335a780c 100644--- a/toonz/sources/toonz/toonz.qrc+++ b/toonz/sources/toonz/toonz.qrc@@ -75,7 +75,8 @@<file>icons/dark/actions/16/save.svg</file><file>icons/dark/actions/16/saveas.svg</file><file>icons/dark/actions/16/saveall.svg</file>- <file>icons/dark/actions/16/gear.svg</file>+ <file>icons/dark/actions/16/gear.svg</file>+ <file>icons/dark/actions/16/gear_check.svg</file><file>icons/dark/actions/16/settings_reset.svg</file><file>icons/dark/actions/16/clear.svg</file><file>icons/dark/actions/16/undo.svg</file>