i have created CLR winforms(.net framework) c++ project, there's two buttons SelectImageBtn and EnhanceBn.
i want to select the folder where the blur images are stored by clicking SelectImageBtn and want to sharp and enhance all the blur images and save the new folder of enhanced images.
i have tried something but getting errors and i don't know weather it will work or not !!
getting error: E0725 name must be a namespace name, on line :
using namespace filesystem;
and error : E0276 name followed by '::' must be a class or namespace name, on line :
for (const auto& file : filesystem::directory_iterator(folderPath))
note : i am newbie to C++, so don't know much about c++
look out the code is i am going right or wrong ? suggestions will be appreciated and thanks in advance!!!
What I have tried:
#include <filesystem>
#include <exception>
#include <opencv2/opencv.hpp>
#include <msclr/marshal_cppstd.h>
#include <string>
namespace ImageEnhancer {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Drawing::Imaging;
using namespace cv;
using namespace std;
using namespace filesystem;
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
}
protected:
~MyForm()
{
if (components)
{
delete components;
}
}
FolderBrowserDialog^ dialog = gcnew FolderBrowserDialog;
private: System::Windows::Forms::Button^ SelectImageBtn;
private: System::Windows::Forms::Button^ EnhanceBn;
protected:
protected:
protected:
protected:
private:
System::ComponentModel::Container^ components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->SelectImageBtn = (gcnew System::Windows::Forms::Button());
this->EnhanceBn = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
this->SelectImageBtn->Location = System::Drawing::Point(134, 152);
this->SelectImageBtn->Name = L"SelectImageBtn";
this->SelectImageBtn->Size = System::Drawing::Size(75, 45);
this->SelectImageBtn->TabIndex = 0;
this->SelectImageBtn->Text = L"Select";
this->SelectImageBtn->UseVisualStyleBackColor = true;
this->SelectImageBtn->Click += gcnew System::EventHandler(this, &MyForm::SelectImageBtn_Click);
this->EnhanceBn->Location = System::Drawing::Point(277, 152);
this->EnhanceBn->Name = L"EnhanceBn";
this->EnhanceBn->Size = System::Drawing::Size(75, 45);
this->EnhanceBn->TabIndex = 1;
this->EnhanceBn->Text = L"Enhance";
this->EnhanceBn->UseVisualStyleBackColor = true;
this->EnhanceBn->Click += gcnew System::EventHandler(this, &MyForm::EnhanceBn_Click);
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(522, 393);
this->Controls->Add(this->EnhanceBn);
this->Controls->Add(this->SelectImageBtn);
this->Name = L"MyForm";
this->Text = L"ImageEnhancer";
this->ResumeLayout(false);
}
#pragma endregion
void enhanceImage(Mat& inputImage, Mat& outputImage)
{
Mat kernel = (Mat_<float>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
filter2D(inputImage, outputImage, -1, kernel);
}
private: System::Void SelectImageBtn_Click(System::Object^ sender, System::EventArgs^ e)
{
try
{
MessageBox::Show("clicked");
dialog->ShowDialog();
string folderPath = msclr::interop::marshal_as<string>(dialog->SelectedPath);
}
catch (const std::exception& exx)
{
}
}
private: System::Void EnhanceBn_Click(System::Object^ sender, System::EventArgs^ e)
{
string folderPath = msclr::interop::marshal_as<string>(dialog->SelectedPath);
for (const auto& file : filesystem::directory_iterator(folderPath))
{
Mat inputImage = imread(file.path().string());
Mat outputImage;
enhanceImage(inputImage, outputImage);
string outputPath = "output/" + file.path().filename().string();
imwrite(outputPath, outputImage);
}
}
};
}