Saturday, 7 November 2015

Create a Gray out or Blur images from the color image using OpenCv in c++

In this post we are going to see how to create a gray out image or blur image from the colored image, To do this we are going to use the Open CV software which is a open source, initially developed by Intel,now supporting by willow garage.

Open CV is a c++ library which is used for real time as well as for offline image processing, and also it can process the Video's to handle objects present in the Videos as a Frames.

Now we start the solution, First we have to download the OpenCV , then extract the Zip,After extraction you can find a 2GB file.In my application i am Extracting the OpenCV to the following Path.

Open CV installed path :  J:\opencv

Now we have to setup the Environment and Visual Studio for our programming.

Environment Setup
1. Right Click Computer and select the properties.
2. Click the Advanced System Settings
3.In the Advanced Tab , select the Environment Variables




4. Now click the New button under the System variable section
5. Give Variable name as  : OPENCV_DIR
6. Give Variable Value as your open cv installed directory , now here i am referencing the vc12 folder
       J:\opencv\build\x86\vc12
7. Click Ok, Now System variable is added.




8.  Next we have to add some value to the Path system variable,
9. Select the Path System Variable and Click Edit.
10. Add the following value at last .  %OPENCV_DIR%\bin




 System Environment variable's are added.

Now we have to configure the visual studio solution.
1. Create a new Win32 console Application in visual studio.
2. Right click on the Project and click the properties
3. Select the General option under the C/C++ category , in that section we have to give value in Additional Include Directories 
           $(OPENCV_DIR)\..\..\Include




4. Above refers the include directory from OPEN CV path .
5. Next click the General under the linker section


6. Give the value for Additional Library Directories
        $(OPENCV_DIR)\lib







7.Select the Input item , in the Additional dependencies , drop down the control and select the Edit to add the libraries.
in the Additional Independence text box add the following values, after adding we can see the values in evaluated value
opencv_ts300.lib
opencv_ts300d.lib
opencv_world300.lib

opencv_world300d.lib






8. Now click ok and start programming.



Now we are going to load an image and process that image to get a Blur image , Gray out image and Canny image.

To store the Image we have to use the Mat Type which is a n-dimensional array class. and also refer some base libraries


#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"

Let we start the coding 


// SampleConsole.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"

#include <iostream>
using namespace std;
using namespace cv;

int main()
{
Mat imageOriginal;
Mat imageGrayScale;
Mat imageBlurred;
Mat imageCanny;

imageOriginal = imread("E:/image.jpg");

if (imageOriginal.empty()) {
cout << "Error in reading image";
return(0);
}
cvtColor(imageOriginal, imageGrayScale, CV_BGR2GRAY);
GaussianBlur(imageOriginal, imageBlurred, cv::Size(5, 5), 1, 5);
Canny(imageBlurred, imageCanny, 100, 200);

imshow("imgOriginal", imageOriginal);
imshow("imgGray", imageGrayScale);
imshow("canny", imageCanny);
imshow("blurred", imageBlurred);

//namedWindow("imgOriginal", CV_WINDOW_AUTOSIZE);
waitKey(0);

destroyWindow("imgOriginal");
destroyWindow("imgGray");
destroyWindow("canny");
destroyWindow("blurred");

return 0;

}



We have to create window to display the images 


Output:



 Original Image


                                                                                                 
                                                                                                        Gray





Canny






Blurred



We can do lot of stuff using the OpenCV, tracking the objects or persons in Real Time Video or Images, Counting the number of persons in the video, Identify the persons in the video or image etc ...


From the post you can learn some basics about how to convert the images in to various modes using Open CV



Winforms UI Automation using C#

In this post we are going to see how to automate the Windows and there operations with out human interaction,Generally this will use in the UI Automation, with out human intervention we are going to do some process in Windows.In this sample i am using the sample exe which is created in winforms where this exe can give result of Add, Sub, Mul, Div Calculation based on the value given in the TextBox, Now we are going to automate this form using the White Framework.


First Download the White Framework, then starts coding ....

I already created the Exe which need to Test, that Exe present in the Following location C:\Users\Goku\Documents\visual studio 2015\Projects\Calc\Calc\bin\Debug\Calc.exe

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestStack.White;
using TestStack.White.Factory;
using TestStack.White.UIItems;
using TestStack.White.UIItems.Finders;
using TestStack.White.UIItems.ListBoxItems;
using TestStack.White.UIItems.WindowItems;
using  System.Diagnostics; 
namespace Automatiom
{
    class WinformAutomation
    {
        public static string FilePath = 
      @"C:\Users\Goku\Documents\visual studio 2015\Projects\Calc\Calc\bin\Debug\Calc.exe";
        Application _application;
        Window _window;

        public void LaunchApplication()
        {
            _application = Application.AttachOrLaunch(new ProcessStartInfo(FilePath));
            _window =  _application.GetWindow(SearchCriteria.ByText("CalcForm"), 
                              InitializeOption.NoCache);
        }

        public void DoOperation()
        {
            TextBox _box1 =  _window.Get<TextBox>(SearchCriteria.ByAutomationId("numtext1"));
            _box1.Text = "5";
            TextBox _box2 = _window.Get<TextBox>(SearchCriteria.ByAutomationId("numtext2"));
            _box2.Text = "6";
        ComboBox OperSelect = _window.Get<ComboBox(SearchCriteria.ByAutomationId("OperList"));

            OperSelect.SetValue("Mul");
        }

        internal void Click()
        {
          Button _btn =   _window.Get<Button>(SearchCriteria.ByAutomationId("DoneBtn"));
            _btn.Click();
        }
    }
}


From the code you can see first application is launched , then we are taking the instance of the particular windows in which we are going to do operations, Next create a instance of each controls through the window instance here i am using the automation Id to get the controls reference, normally control name is mention in automation id.

Finally get the instance of button and fires the click event.To find the automation id of each control we can use the UISPy tool which get the id as well as many properties of all windows present inside the Operating System.

Sample :



When we launch the application this will trigger a CalcForm.Exe to launch and the place the value in the textbox's ,select the value in combobox and finally clicks the button.

Output:
********




























Sunday, 1 November 2015

Microsoft Windows 10 Memory Leak operating system consuming lot of Ram for running the applications in Operating system

               Normally when we heard about the free update of windows 10 for existing users, looks cool for us. but after upgrading it become a night mare for many users who uses this operating systems for day to day activities.Because most of the Ram is consumed by the Operating system to run the applications.

Likewise in my system also Ram usage is consumed by the operating system by huge, When just running the Two applications it took 80% of the Total Ram, These makes to stop running the Windows Phone Emulators.

After many analysis it seems that some services is keep on running in the system which increases the Ram , it may me Drivers which leak Memory or It may be a Background WinRT apps. But it tried Two Solutions which makes my system to comes back to normal usage of Ram.

Step 1: 

  •  Go to the settings.
  • Click the System
  • Navigate to the Notifications & Actions menu
  • Disable or off the show me tips about windows
  • Restart the System  







Step 2 :

  • Install the Kingsoft PC Dcotor
  • Go to the main menu and Run optimize and click Fix all
  • Select the SysBooster and run it 
  • Now the Ram consumed is release my memory

Task Manager Before the SysBooster Run









Task Manager  After the SysBooster Run




We can see the Decrease in the Ram consumption, But none of the applications are closed.


After closing two application system reduce to 33% memory consumption, but basically while load the OS it shows me 45% of Ram consumed






     SysBooster  is the key application to reduce the memory leakage, but how a third party application can able to reduce the memory consumption, with out closing any application. Memory leak in windows 10 is resolve by this application but , again the OS raises the memory consumption after sometime. 



Why Microsoft had release this kind of Memory leak operating system ?

Memory leak issue is somewhat resolve by Third party application like Kingsoft PC Doctor ...... We can wait for Microsoft patch which will patch the memory leak issue

Even in this step also there is something we need to do is we have to run the system booster every 30 minutes or later based on memory consumtion, because again system raises its consumption after sometime.But some how we can drop the memory usage to the normal level by Third party application