Posts

Showing posts from September, 2018

Using OpenCV for image handling operations

1. Load an image and display it [code language="cpp"] //Loads image and displays #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> int main() { cv::Mat image = cv::imread("spots2.jpg", CV_LOAD_IMAGE_COLOR); if( false == image.data ) { std::cout << "Could not open or find the image" << std::endl ; return -1; } cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE ); cv::imshow( "Display window", image ); cv::waitKey(0); return 0; } [/code] 2. Add a trackbar to blend two images [code language="cpp"] #include <cv.h> #include <highgui.h> const int alpha_slider_max = 100; int alpha_slider; double alpha; double beta; cv::Mat src1; cv::Mat src2; cv::Mat dst; void on_trackbar( int, void* ) { alpha = (double) alpha_slider/alpha_slider_max ; beta = ( 1.0 - alpha ); cv::add...

Handling mouse event commands in Listview controls in WPF / MVVM

Image
Some instructions on how to intercept events when clicking on Listview controls in WPF / MVVM. Step 1: Create a new WPF application in Visual Studio Step 2: Ensure necessary resources are added System.IO.Compression System.IO.Compression.FileSystem System.Windows.Interactivity Step 3: Add the MainWindowViewModel class MainWindowViewModel.cs [code language="csharp"] using System.Collections.Generic; using System.Windows; using System.Windows.Input; namespace ListviewEvent { public class Item { public Item(string name, string matches) { Name = name; Matches = matches; } public string Name { get; set; } public string Matches { get; set; } } public class ItemHandler { public ItemHandler() { Items = new List<Item>(); } public List<Item> Items { get; private set; } public void Add(Item item) { Items.Add(item); } } ...

How to automatically increment build versions in Visual Studio

Image
Some instructions on how to automatically increment the build number of your Visual Studio project. What was important to me was to automatically increment the build and version number of my executable files using Visual Studio. Some important StackOverflow links helped me to achieve this: https://stackoverflow.com/questions/356543/can-i-automatically-increment-the-file-build-version-when-using-visual-studio https://stackoverflow.com/questions/826777/how-to-have-an-auto-incrementing-version-number-visual-studio To demonstrate the instructions contained in the StackOverflow links, first create a new Visual Studio project. For simplicity, choose a .NET console application: Notice that a file called AssemblyInfo.cs is automatically created: Modify the AssemblyInfo.cs file, so that the AssemblyVersion attribute ends with an asterisk. Also comment out or remove the second of these lines, AssemblyFileVersion, so that we just have the following: AssemblyInfo.cs ...

Reporting the percentage progress of large file downloads in C# / WPF

Image
When downloading very large files from an online source, it can sometimes appear that the program has frozen or crashed when in fact it is still busy downloading and/or writing to disk. This post that shows you how to report the percentage of large file sizes in addition to the overall progress of all downloads and is demonstrated using a WPF application using the MVVM (Model View ViewModel) pattern. Useful StackOverflow link: https://stackoverflow.com/questions/21169573/how-to-implement-progress-reporting-for-portable-httpclient Step 1: Create a new Visual Studio WPF application Step 2: Create the View Update the MainWindow.xaml to include the necessary progress bar, button control, text controls etc. MainWindow.xaml [code language="csharp"] <Window x:Class="DownloadProgress.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml...