92 lines
2.4 KiB
Plaintext
92 lines
2.4 KiB
Plaintext
|
# Qt 读写 ini
|
||
|
QSettings setting(ini_path, QSettings::IniFormat);
|
||
|
// 读
|
||
|
int value = setting.value("R/lower").toInt(); // 无文件或者无字段不报错,值为0
|
||
|
// 写
|
||
|
settings.setValue("General/Age", 30);
|
||
|
|
||
|
# Qt 获取当前 exe 路径
|
||
|
QString exe_path = QCoreApplication::applicationDirPath();
|
||
|
QDir dir(exe_path);
|
||
|
QString ini_path = dir.absoluteFilePath("ImageProcess.ini");
|
||
|
|
||
|
# Qt 选择文件夹
|
||
|
QFileDialog::getExistingDirectory(parent, u8"选择文件夹", QDir::homePath());
|
||
|
|
||
|
# Qt 确认对话框
|
||
|
QMessageBox questionBox(parent);
|
||
|
questionBox.setText(content);
|
||
|
questionBox.setWindowTitle(title);
|
||
|
questionBox.setIcon(QMessageBox::Question);
|
||
|
questionBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||
|
int result = questionBox.exec();
|
||
|
if (result != QMessageBox::Yes) {
|
||
|
return false;
|
||
|
} else {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
# Qt 消息提示
|
||
|
QMessageBox::information(parent, u8"提示", infomation);
|
||
|
|
||
|
# windows 获取CPU逻辑处理器数量
|
||
|
SYSTEM_INFO sysInfo;
|
||
|
GetSystemInfo(&sysInfo);
|
||
|
int numCores = sysInfo.dwNumberOfProcessors;
|
||
|
|
||
|
# Qt QImage 和 opencv 的转换
|
||
|
cv::Mat image_ = cv::imread(path);
|
||
|
cv::cvtColor(image_, image_, cv::COLOR_BGR2RGB);
|
||
|
QImage(image_.data, image_.cols, image_.rows, image_.step, QImage::Format_RGB888);
|
||
|
|
||
|
# Qt 遍历文件
|
||
|
QStringList files = dir.entryList(QDir::Files);
|
||
|
|
||
|
# Qt 读写 txt
|
||
|
QFile file(list_file);
|
||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||
|
message(this, u8"打开文件" + list_file + u8"失败");
|
||
|
return;
|
||
|
}
|
||
|
QTextStream in(&file);
|
||
|
QString tmp;
|
||
|
while (!in.atEnd()) {
|
||
|
in >> tmp;
|
||
|
}
|
||
|
file.close();
|
||
|
|
||
|
# opencv 调节亮度
|
||
|
image_.convertTo(image_, -1, 1, light);
|
||
|
|
||
|
# C++ 统计运行时间
|
||
|
auto start = std::chrono::high_resolution_clock::now();
|
||
|
auto end = std::chrono::high_resolution_clock::now();
|
||
|
auto duration = std::chrono::duration_cast<std::chrono::seconds>(end - start);
|
||
|
int time = duration.count();
|
||
|
|
||
|
# opencv 更改 RGB 值
|
||
|
std::vector<cv::Mat> channels;
|
||
|
cv::split(img, channels);
|
||
|
channels[0] += r;
|
||
|
channels[1] += g;
|
||
|
channels[2] += b;
|
||
|
cv::merge(channels, img);
|
||
|
|
||
|
# Qt 限制 QLineEdit 输入整数
|
||
|
QIntValidator* valid = new QIntValidator(this);
|
||
|
valid->setRange(1, INT_MAX);
|
||
|
ui.edPicNo->setValidator(valid);
|
||
|
|
||
|
# Qt 窗口变化事件
|
||
|
bool MainWidget::event(QEvent * ev)
|
||
|
{
|
||
|
if (ev->type() == QEvent::Resize) {
|
||
|
|
||
|
}
|
||
|
return QWidget::event(ev);
|
||
|
}
|
||
|
|
||
|
# Qt QLabel 显示图片
|
||
|
QImage img = img.scaled(w, h, Qt::KeepAspectRatio);
|
||
|
ui.label->setPixmap(QPixmap::fromImage(img));
|
||
|
ui.label->show();
|