Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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;


	/// <summary>
	/// Summary for MyForm
	/// </summary>
	public ref class MyForm : public System::Windows::Forms::Form
	{
	public:
		MyForm(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~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:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container^ components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->SelectImageBtn = (gcnew System::Windows::Forms::Button());
			this->EnhanceBn = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// SelectImageBtn
			// 
			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);
			// 
			// EnhanceBn
			// 
			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);
			// 
			// MyForm
			// 
			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

		// Function to enhance a single image
		void enhanceImage(Mat& inputImage, Mat& outputImage)
		{
			// Code to enhance image using OpenCV functions goes here
			// For example, sharpening the image:
			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");
			// Create FolderBrowserDialog to select folder
			
			dialog->ShowDialog();

			// Store selected folder path
			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);
		
		// Loop through all files in the selected folder
		for (const auto& file : filesystem::directory_iterator(folderPath))
		{
			// Load image using OpenCV
			Mat inputImage = imread(file.path().string());

			// Create output image
			Mat outputImage;

			// Enhance image
			enhanceImage(inputImage, outputImage);

			// Save enhanced image to new folder
			string outputPath = "output/" + file.path().filename().string();
			imwrite(outputPath, outputImage);
		}

	}
		  

	};
}
Posted
Updated 12-Mar-23 2:40am
Comments
Mohamed Alaa Mar2023 11-Mar-23 1:08am    
Given two strings S and T. Print 2 lines that contain the following in the same order:

Print the length of S and T separated by space.
Print a new string that contains S and T separated by a space.
For more clarification see the example below.

Input
The first line contains a string S (1 ≤ |S| ≤ 103) where |S| is the length of S.

The second line contains a string T (1 ≤ |T| ≤ 103) where |T| is the length of T.

Output
Print the answer required above.
Mohamed Alaa Mar2023 11-Mar-23 1:09am    
I want to know the solution to the question
Dave Kreskowiak 11-Mar-23 12:42pm    
The only code you get is the code YOU write. Nobody is going to do your homework for you.
Dave Kreskowiak 12-Mar-23 11:45am    
You posted your "question" as a comment on a completely unrelated topic. Your question is going to be ignored.

The /std option is used to control version-specific standard features of the ISO C or C++ programming language in a compiler.
https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version
However, according to your sample code you are using C++/CLI. This is a variant of the ISO C++ programming language developed by Microsoft.

You don't seem to be clear about the difference.
 
Share this answer
 
okay i found the solutions for getting errors
i was using
ISO C++14 Standard (/std:c++14)
instead of upgraded version
ISO C++17 Standard (/std:c++17)


i fix the problem following steps

To switch to C++17 or later, you need to modify the compiler options. Here are the steps to switch to C++17 in Visual Studio:

-> Right-click on your project in the Solution Explorer and select "Properties".

->Select "C/C++" and then "Language" from the left-hand menu.

->In the "C++ Language Standard" drop-down, select "ISO C++17 Standard (/std:c++17)".

->Click "Apply" and then "OK" to save your changes.

If you are using a different compiler, you will need to consult the documentation for that compiler to find out how to switch to C++17.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900