Istanbul, Turkey

Configuring OpenCV 3.1 and Visual Studio 2015

This is not a new thing actually, and as far as I remember this is my second time configuring this. However, I found problem on myself ūüėź I keep forgeting how to configure and connect openCV library with VS2015, especially in C++ language. As we know the environment is different than C# environment. So I decided to create one post for my own documentation. Because everytime I tried new installation, I keep facing the similar error but I forgot how to solve it and ended up with googling over the same problem so many time.

Configuring OpenCV 3.1 with VS2015

  1. Assume that you’ve installed VS2015
  2. Download the newest OpenCV library from here. In my case version 3.1 in .exe format.
  3. Extract the .exe file by clicking it.
  4. Copy the extracted file into C:// drive
  5. Configure the windows environment variable (System Properties -> Advances system settings -> Environment Variable…):
    1. Add new variable OPENCV_DIR with Value the directory of VC14 bin (C:\opencv\build\x64\vc14\bin)
    2. Add value to “Path” variable with¬†C:\opencv\build\x64\vc14\bin

 

Calling the openCV library from VS2015 IDE

If you decide to use C++, you have to setting the properties everytime you create new project. To make it easy, create property sheet so that you can import it for other project.

  1. Create Property Sheet for OpenCV 3.1
    1. Click View -> Other Windows -> Property Manager
    2. Right Click in the Project Name -> Add New Project Property Sheet
    3. Give it name, for me OpenCV3.1
  2. Setting VC++ Directories
    1. Include Directories : C:\opencv\build\include
    2. Library Directories: C:\opencv\build\x64\vc14\lib
  3. Setting Linker
    1. Click Input -> Additional Dependencies -> Add opencv_world310d.lib (for Debug)

 

Testing OpenCV Hello World

Write following code to test whether it has been linked or not. Put your tested image into your project folder to make it easy, or change the imread directory as per your image location.

#include "stdafx.h"
#include <opencv2\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include 
 
int main(int argc, char** argv)
{
	cv::Mat image;
	image = cv::imread("takanyan.jpg");
	cv::imshow("testing",image);
	cvWaitKey(0);
	return 0;
}

Voila~ done.

TroubleShooting

  • Cannot find or open the PDB file

Change the Setting of Microsoft Symbol. Tools -> Options -> Debugging -> Symbols and check “Microsoft Symbol Servers”

  • Target Platform related error

Change the target platform into x64

 

The IdolM@ster Cinderella Girls Starlight Stage – ChieriBlossom

Let me introduce my second special team in deresute game! Special Team here is a team where the 5 members are the same idol star haha

As you can see, I decided “ChieriBlossom” as a team name. I think you can guess why I gave that name hehehe Yeah, because the main star is Chieri Ogata! This team was complete on Thursday, 2016 September 8th.

So, here is my ChieriBlossom Team:

Chieri Ogata (SSR) – Center

Chieri Ogata (SR) –¬†Beyond The Star Live Groove Event

Chieri Ogata (Normal)

Chieri Ogata (SR)

Chieri Ogata (SR) Awakened – Beyond The Star Live Groove Event

 

 

 

Capture Point Cloud with PCL 1.8 and Kinect V2 #3 ‚Äď OpenNI2 Grabber

After trying long way to capture Point Cloud without Grabber, there is easier way to capture Point Cloud with Kinect. Utilize OpenNI2 Grabber.But here, make sure you add additional Property Sheet for OpenNI2

OpenNI2.props

C/C++ Additional Include Dir

C:\Program Files\OpenNI2\Include

Linker Additional Library Dir

C:\Program Files\OpenNI2\Lib;

Linker Input

OpenNI2.lib

Make Sure OpenNI is set in the Environment Variables

OPENNI2_INCLUDE64 -> Folder location of Include folder
OPENNI2_LIB64 -> Folder location of Library folder
OPENNI2_REDIST64 -> Folder location of OpenNI Redist folder OpenNI2\Redist

above setting are in the System Variables of Environment Variables. And add also value %OPENNI2_REDIST64%; in the Path Variables.

If we have done with config above, mostly we can avoid error related to external library dependencies.

Please refer to reference below for the Source Code. The original tutorial from PCL website (ref no 2 and 3) is the old OpenNI version 1 which is not supported anymore, especially with VS2015. Moreover we use OpenNI2 now (ref no 1). There He provided us with Kinect2_grabber.h. Or if you do not want to use that header, we still can use only PCL header.

The only difference is the location of OpenNIGrabber method.

Code used in OpenNI version 1

pcl::Grabber* interface = new pcl::OpenNIGrabber();
 
boost::function::ConstPtr&)> f =
boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);
 
interface->registerCallback (f);
 
interface->start ();

You will not find new pcl::OpenNIGrabber() in Open NI2 library. So change that code with new pcl::io::OpenNI2Grabber()
do not forget that the header also different in PCL 1.8 for OpenNI2 , the header is #include <pcl\io\openni2_grabber.h>

Only some differences.

But for me, I used reference no 1 since it was easier. sometimes OpenNI2 driver didn’t installed properly, like my case, I still have trouble using OpenNI2

If you found some error, please refer to my previous posting here

References: 1 | 2 | 3 |

Error Troubleshooting:

1.PCL::IOException (updated soon when I solved it)

Capture Point Cloud with PCL 1.8 and Kinect V2 #2 ‚Äď Without Grabber

After you go through PCL and Kinect Setup. You can start writing program. This time, I will try to capture the Point Cloud without using Grabber. Grabber is method provided by OpenNI library. So in this program, you do not need to add Open NI module inside your project. this program only use Kinect and PCL library as reference.

Initialization:

  • Create Win32 C++ Console Project
  • Add existing Property Sheet: PCL.props and Kinect SDK.props as configured here
  • Declare Include header as follows:

#include “stdafx.h”
#define NOMINMAX
#include <Windows.h>
#undef NOMINMAX
#include <Kinect.h>
#include <pcl\visualization\cloud_viewer.h>
#include <pcl\common\projection_matrix.h>
#include <pcl\point_cloud.h>
#include <iostream>

Something to notice is #define NOMINMAX and windows.h header. declare this before we declare PCL header and define NOMINMAX before windows.h. Because if you put it wrong, can cause another error while debugging.

I will not re-write the code, because the code shown in the reference is correct. please refer to below link. I just want to make some note about this program ūüôā

References: 1 | 2 |

Result:

Error Troubleshooting:

1.Header Placement of NOMINMAX and Windows.h

Error 2589 and Error 2143 will be shown.¬†‘identifier’ : illegal token on right side of ‘::’

Solve: rearrange the header placement. declare NOMINMAX before windows.h and PCL header after that.

Reference: 1 | 2 |

2.LNK2019 unresolved external symbol

Solve: this was my stupid mistake haha I did the uncomplete config for PCL.props. I forgot to declare Additional Library Dependencies in the property, so that my program could not find the symbol . So, I did solve it with adding those many .lib in the setting. (refer to setup page)

3.Compiler Error

Error  4996 shown.

Solve: Add additional definition after header declaration

#ifdef _DEBUG
#define _SCL_SECURE_NO_WARNINGS
#endif

4.argument of type “ColorSpacePoint” is incompatible / too few arguments in function call

This error was also my silly mistake. haha I mistakenly use another method. This error was related to Mapping method. MapDepthPointToColorSpace and MapDepthPointToCameraSpace . I got this error because I use different method (MapDepthPointsToCameraSpace and MapDepthPointsToColorSpace). Points , not Point.

Solve: change using the correct method. I don’t know why my Intellisense is so slow. thats why I did not realize that there are two similar method there.

If you found another error, try to check the library, header, and property setting.

Capture Point Cloud with PCL 1.8 and Kinect V2 #1 – Setup

For the sake of my individual project, I have been investigating many libraries and try tutorial of each library, change programming language from C# to C++, and many things. Those are only for utilizing potential of Microsoft Kinect v2 with its depth camera. And after 1 month, I hope I made right decision by combinating PCL and Kinect, will bring me to the end of this project.

But, I’ll tell you that doing setup for this library was not easy, especially for Windows and Visual Studio. You have to make sure of every detail and do not ever miss any configuration in order to make it run. For me, even to start the “Hello World” Project, I spent 1 week for running it, through a lot of unfamiliar troubleshooting because c++ is new thing for me.

I made this post also as my own reminder, just in case I forget some detail. ūüėÄ And I also send my huge gratitude for everyone who post tutorial and error troubleshooting (see the reference link at the bottom)

My Dev Environment

  • Windows 10 x64 Education License
  • Visual Studio Express 2015
  • Language C++
  • Microsoft Kinect Version 2
  • PCL 1.8.0 RC1

Installation

  • Kinect for Windows SDK 2.0
  • Point Cloud Library for Visual Studio 2015 (vc14). I was so thankful to him because He made installation of PCL for VS 2015 became easier than it should have been. You have 2 options for installing this library:
    • 1) use all-in-installer from his website. Make sure all 3rd Party are installed:
      • Boost 1.6
      • Eigen 3,
      • FLANN,
      • OpenNI2,
      • Qhull,
      • VTK 7.0
    • 2) build with your own compiler. But, if you choose 2nd option, you have to install many 3rd party separately also. And the possibility of getting error also high. My friend said that building in other OS other than Windows was easier and not complex. Follow the link above to build separately.

I have tried both options anyway. And first option was faster and easier. If the installer asking whether to add Path in the system or not, choose Yes. This was regarding Environment Variable configuration in our OS.

Configuration

1)Environment Variables

This is new things for me. So far, I never find this configuration haha or probably case by case also. To put it simply, this setting is used as startup, where you define the dependent library used by the program, such as library declaration. This is important, some of tutorial did not mention that what they wrote is this configuration. They only write the configuration variables.

How:
Go to Properties of File Explorer by Right Click it. Then Choose Advanced System Settings. And Click Environment Variables. And add New configuration as follows:

 VariableValue
User VariablePCL_ROOTC:\Program Files\PCL 1.8.0 (your PCL folder)
System VariablePath (already exist. make sure following value are written)%PCL_ROOT%\bin;
%PCL_ROOT%\3rdParty\FLANN\bin;
%PCL_ROOT%\3rdParty\VTK\bin;
%OPENNI2_REDIST64%;

Note: This configuration is for x64 installer, if using x86, the folder will be at Program Files (x86). Btw x64 or x86 here means the PCL installer we used, not related with our operating system. And for OpenNI configuration is optional. If you use Kinect as camera, probably you need it too.

2) VS2015 Property Setting

Before, I did not know that this setting can be saved as .prop file. So every time I start new project, I have to do this routine every time which was really wasting time haha So, this configuration is making property sheets for VS and can be used in every project. We will make 2 Files: PCL.prop and KinectSDK.prop

How:

  1. Create Empty C++ Project
  2. Show Property Manager window, by clicking View -> Other Windows -> Property Manager
  3. There will be 4 folders if you use x64. Debug and Release Folder for your solution project
  4. In the Solution name, Right Click it and Add New Project Property Sheet. And give it name.
  5. The files will be available in every folder. Choose in any folder the property sheet that we want to configure. Right Click -> Properties
  6. The most important is C/C++ and Linker Menu. Configure the property as following:

 

PCL.props

C/C++ Menu in Additional Include Directories

C:\Program Files\PCL 1.8.0\include\pcl-1.8\

C:\Program Files\PCL 1.8.0\3rdParty\VTK\include\vtk-7.0
C:\Program Files\PCL 1.8.0\3rdParty\Boost\include\boost-1_60
C:\Program Files\PCL 1.8.0\3rdParty\Qhull\include
C:\Program Files\PCL 1.8.0\3rdParty\FLANN\include
C:\Program Files\PCL 1.8.0\3rdParty\Eigen\eigen3\

Linker Menu -> General-> Additional Library Directories

C:\Program Files\PCL 1.8.0\lib
C:\Program Files\PCL 1.8.0\3rdParty\VTK\lib
C:\Program Files\PCL 1.8.0\3rdParty\Qhull\lib
C:\Program Files\PCL 1.8.0\3rdParty\FLANN\lib
C:\Program Files\PCL 1.8.0\3rdParty\Boost\lib

Linker Menu->Input-> Additional Dependencies

pcl_common_release.lib
pcl_features_release.lib
pcl_filters_release.lib
pcl_io_ply_release.lib
pcl_io_release.lib
pcl_kdtree_release.lib
pcl_keypoints_release.lib
pcl_ml_release.lib
pcl_octree_release.lib
pcl_outofcore_release.lib
pcl_people_release.lib
pcl_recognition_release.lib
pcl_registration_release.lib
pcl_sample_consensus_release.lib
pcl_search_release.lib
pcl_segmentation_release.lib
pcl_stereo_release.lib
pcl_surface_release.lib
pcl_tracking_release.lib
pcl_visualization_release.lib
libboost_atomic-vc140-mt-1_60.lib
libboost_chrono-vc140-mt-1_60.lib
libboost_container-vc140-mt-1_60.lib
libboost_context-vc140-mt-1_60.lib
libboost_coroutine-vc140-mt-1_60.lib
libboost_date_time-vc140-mt-1_60.lib
libboost_exception-vc140-mt-1_60.lib
libboost_filesystem-vc140-mt-1_60.lib
libboost_graph-vc140-mt-1_60.lib
libboost_iostreams-vc140-mt-1_60.lib
libboost_locale-vc140-mt-1_60.lib
libboost_log-vc140-mt-1_60.lib
libboost_log_setup-vc140-mt-1_60.lib
libboost_math_c99-vc140-mt-1_60.lib
libboost_math_c99f-vc140-mt-1_60.lib
libboost_math_c99l-vc140-mt-1_60.lib
libboost_math_tr1-vc140-mt-1_60.lib
libboost_math_tr1f-vc140-mt-1_60.lib
libboost_math_tr1l-vc140-mt-1_60.lib
libboost_mpi-vc140-mt-1_60.lib
libboost_prg_exec_monitor-vc140-mt-1_60.lib
libboost_program_options-vc140-mt-1_60.lib
libboost_random-vc140-mt-1_60.lib
libboost_regex-vc140-mt-1_60.lib
libboost_serialization-vc140-mt-1_60.lib
libboost_signals-vc140-mt-1_60.lib
libboost_system-vc140-mt-1_60.lib
libboost_test_exec_monitor-vc140-mt-1_60.lib
libboost_thread-vc140-mt-1_60.lib
libboost_timer-vc140-mt-1_60.lib
libboost_type_erasure-vc140-mt-1_60.lib
libboost_unit_test_framework-vc140-mt-1_60.lib
libboost_wave-vc140-mt-1_60.lib
libboost_wserialization-vc140-mt-1_60.lib
flann_cpp_s.lib
qhullstatic.lib
vtkalglib-7.0.lib
vtkChartsCore-7.0.lib
vtkCommonColor-7.0.lib
vtkCommonComputationalGeometry-7.0.lib
vtkCommonCore-7.0.lib
vtkCommonDataModel-7.0.lib
vtkCommonExecutionModel-7.0.lib
vtkCommonMath-7.0.lib
vtkCommonMisc-7.0.lib
vtkCommonSystem-7.0.lib
vtkCommonTransforms-7.0.lib
vtkDICOMParser-7.0.lib
vtkDomainsChemistry-7.0.lib
vtkexoIIc-7.0.lib
vtkexpat-7.0.lib
vtkFiltersAMR-7.0.lib
vtkFiltersCore-7.0.lib
vtkFiltersExtraction-7.0.lib
vtkFiltersFlowPaths-7.0.lib
vtkFiltersGeneral-7.0.lib
vtkFiltersGeneric-7.0.lib
vtkFiltersGeometry-7.0.lib
vtkFiltersHybrid-7.0.lib
vtkFiltersHyperTree-7.0.lib
vtkFiltersImaging-7.0.lib
vtkFiltersModeling-7.0.lib
vtkFiltersParallel-7.0.lib
vtkFiltersParallelImaging-7.0.lib
vtkFiltersProgrammable-7.0.lib
vtkFiltersSelection-7.0.lib
vtkFiltersSMP-7.0.lib
vtkFiltersSources-7.0.lib
vtkFiltersStatistics-7.0.lib
vtkFiltersTexture-7.0.lib
vtkFiltersVerdict-7.0.lib
vtkfreetype-7.0.lib
vtkGeovisCore-7.0.lib
vtkgl2ps-7.0.lib
vtkhdf5-7.0.lib
vtkhdf5_hl-7.0.lib
vtkImagingColor-7.0.lib
vtkImagingCore-7.0.lib
vtkImagingFourier-7.0.lib
vtkImagingGeneral-7.0.lib
vtkImagingHybrid-7.0.lib
vtkImagingMath-7.0.lib
vtkImagingMorphological-7.0.lib
vtkImagingSources-7.0.lib
vtkImagingStatistics-7.0.lib
vtkImagingStencil-7.0.lib
vtkInfovisCore-7.0.lib
vtkInfovisLayout-7.0.lib
vtkInteractionImage-7.0.lib
vtkInteractionStyle-7.0.lib
vtkInteractionWidgets-7.0.lib
vtkIOAMR-7.0.lib
vtkIOCore-7.0.lib
vtkIOEnSight-7.0.lib
vtkIOExodus-7.0.lib
vtkIOExport-7.0.lib
vtkIOGeometry-7.0.lib
vtkIOImage-7.0.lib
vtkIOImport-7.0.lib
vtkIOInfovis-7.0.lib
vtkIOLegacy-7.0.lib
vtkIOLSDyna-7.0.lib
vtkIOMINC-7.0.lib
vtkIOMovie-7.0.lib
vtkIONetCDF-7.0.lib
vtkIOParallel-7.0.lib
vtkIOParallelXML-7.0.lib
vtkIOPLY-7.0.lib
vtkIOSQL-7.0.lib
vtkIOVideo-7.0.lib
vtkIOXML-7.0.lib
vtkIOXMLParser-7.0.lib
vtkjpeg-7.0.lib
vtkjsoncpp-7.0.lib
vtklibxml2-7.0.lib
vtkmetaio-7.0.lib
vtkNetCDF-7.0.lib
vtkNetCDF_cxx-7.0.lib
vtkoggtheora-7.0.lib
vtkParallelCore-7.0.lib
vtkpng-7.0.lib
vtkproj4-7.0.lib
vtkRenderingAnnotation-7.0.lib
vtkRenderingContext2D-7.0.lib
vtkRenderingContextOpenGL-7.0.lib
vtkRenderingCore-7.0.lib
vtkRenderingFreeType-7.0.lib
vtkRenderingGL2PS-7.0.lib
vtkRenderingImage-7.0.lib
vtkRenderingLabel-7.0.lib
vtkRenderingLIC-7.0.lib
vtkRenderingLOD-7.0.lib
vtkRenderingOpenGL-7.0.lib
vtkRenderingVolume-7.0.lib
vtkRenderingVolumeOpenGL-7.0.lib
vtksqlite-7.0.lib
vtksys-7.0.lib
vtktiff-7.0.lib
vtkverdict-7.0.lib
vtkViewsContext2D-7.0.lib
vtkViewsCore-7.0.lib
vtkViewsInfovis-7.0.lib
vtkzlib-7.0.lib
OpenNI2.lib

Kinect SDK.prop

C/C++ Menu in Additional Include Directories

C:\Program Files\Microsoft SDKs\Kinect\v2.0_1409\inc

Linker Menu -> General-> Additional Library Directories

C:\Program Files\Microsoft SDKs\Kinect\v2.0_1409\Lib\x64

Linker Menu->Input-> Additional Dependencies

kinect20.lib

If you want to use the same property sheet, just Add Existing Prop sheet in the project property manager.

Now… All the configuration and setting for PCL library and Kinect SDK Library are done! now you can start programming stuff. ūüėÄ

And if you read in PCL official website that we need to add CmakeLists.txt inside the project folder, with this config, we can skip this step. Honestly using Cmake is kind of not easy if you found many abnormal case haha

References: 1 | 2 | 3 | 4 |

Detect Basic Shape in Image with WPF EmguCV

Second tutorial that I have tried was how to detect circles, rectangles and triangles in an image. Like the previous program, I will use WPF and C# for the following program. When you start new project, do not ever forget to do basic setting for the project.

Basic Setting:

  • Copy paste the library (opencv_ffmpeg310_64.dll,¬†opencv_core220.dll,¬†opencv_imgproc220.dll) into Debug folder inside your project folder.
  • Add existing item into the solution explorer in the Visual Studio. Add 3 libraries mentioned above.
  • Copy paste¬†cvextern.dll also into our project folder.
  • Change the Advanced Properties into “Copy Always”

  • Add new references into References. Add Emgu.CV.UI, Emgu.CV.World and Add Emgu. Util. If needed, I also add System.Drawing into the references.
  • Add existing class provided by EmguCV: BitmapSourceConverter.cs
  • Change the Build Properties into x64 setting. Please refer to previous tutorial.
  • Declare the using statement before begin writing your code.
using Emgu.CV.Structure;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.CvEnum;
using Microsoft.Win32;
using Emgu.CV.Util;

Start Program:

Now We can start writing the algorithm. First of all, take care of the GUI first. I will put the output image into Image Control in WPF. the XAML code as follow:

<Grid>
  <Grid.ColumnDefinitions>
   <ColumnDefinition />
   <ColumnDefinition />
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
   <RowDefinition Height="*"/>
   <RowDefinition Height="*"/>
   <RowDefinition Height="auto"/>
  </Grid.RowDefinitions>
 <Image x:Name="myImage" Margin="5" />
 <Image Grid.Column="1" x:Name="myGreyImage" Margin="5"/>
 <Image Grid.Row="1" x:Name="detectCircle" Margin="5"/>
 <Image Grid.Row="1" Grid.Column="1" x:Name="detectRectangle" Margin="5"/>
 <Button Grid.Column="1" Grid.Row="2" x:Name="testButton" Content="Load Image" Click="testButton_Click" HorizontalAlignment="Right" VerticalAlignment="Bottom" Height="44" Width="92"/>
</Grid>

I create two methods,first for detecting circles and second for detecting rectangles and triangles. Below are the code:

Detect and Draw detected circles:

private static Image<Bgr, byte> detectCircle(Image<Bgr, byte> image)
{
Image<Gray, byte> imageGrey = image.Convert<Gray, byte>();
 
double cannyThreshold = 180.0;
double circleAccumulatorThreshold = 120;
CircleF[] circles = CvInvoke.HoughCircles(imageGrey, HoughType.Gradient,
2.0, 20.0, cannyThreshold,
circleAccumulatorThreshold, 5);
 
//canny and edge detection
double cannyThresholdLinking = 120.0;
UMat cannyEdges = new UMat();
CvInvoke.Canny(imageGrey, cannyEdges, cannyThreshold, cannyThresholdLinking);
 
LineSegment2D[] lines = CvInvoke.HoughLinesP(cannyEdges, 1, Math.PI / 45.0,
20, 30, 10);
Image<Bgr, byte> circleImage = image.CopyBlank();
foreach (CircleF circle in circles)
circleImage.Draw(circle, new Bgr(255, 0, 0), 5);
 
return circleImage;
}

Detect and Draw detected rectangles and triangles:

 

 private static Image<Bgr, byte> detectRectTri(Image<Bgr, byte> image)
 {
 Image<Gray, byte> imageGrey = image.Convert<Gray, byte>();
 
 List<Triangle2DF> triangleList = new List<Triangle2DF>();
 List<RotatedRect> boxList = new List<RotatedRect>();
 
 UMat cannyEdges = new UMat();
 double cannyThreshold = 180.0;
 double cannyThresholdLinking = 120.0;
 CvInvoke.Canny(imageGrey, cannyEdges, cannyThreshold, cannyThresholdLinking);
 
 
 using (VectorOfVectorOfPoint countours = new VectorOfVectorOfPoint())
 {
 
 CvInvoke.FindContours(cannyEdges, countours, null, RetrType.List,
 ChainApproxMethod.ChainApproxSimple);
 int count = countours.Size;
 for (int i = 0; i < count; i++)
 {
 using (VectorOfPoint kontur = countours[i])
 using (VectorOfPoint approxContour = new VectorOfPoint())
 {
 CvInvoke.ApproxPolyDP(kontur, approxContour, CvInvoke.ArcLength(kontur, true) * 0.05, true);
 if (CvInvoke.ContourArea(approxContour, false) > 250) //only consider contours with area greater than 250
 {
 if (approxContour.Size == 3) //the countour has 3 vertices. it is triangle
 {
 System.Drawing.Point[] pts = approxContour.ToArray();
 triangleList.Add(new Triangle2DF(pts[0], pts[1], pts[2]));
 }
 else if (approxContour.Size == 4) //rectangle
 {
 //determine if allthe angles in the contour are within [80,100] degree
 bool isRectangle = true;
 System.Drawing.Point[] pts = approxContour.ToArray();
 LineSegment2D[] edges = Emgu.CV.PointCollection.PolyLine(pts, true);
 
 for (int j = 0; j < edges.Length; j++)
 {
 double angle = Math.Abs(
 edges[(j+i)% edges.Length].GetExteriorAngleDegree(edges[j]));
 if (angle < 80 || angle > 100)
 {
 isRectangle = false;
 break;
 }
 
 }
 if (isRectangle) boxList.Add(CvInvoke.MinAreaRect(approxContour));
 }
 }
 }
 }
 }
 
 Image<Bgr, byte> triRectImage = image.CopyBlank();
 foreach (Triangle2DF triangle in triangleList)
 triRectImage.Draw(triangle, new Bgr(0, 255, 0), 5);
 foreach (RotatedRect box in boxList)
 triRectImage.Draw(box, new Bgr(0, 0, 255), 5);
 
 return triRectImage;
 }

Button Event Handler:

 private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openPic = new OpenFileDialog();
            if (openPic.ShowDialog() == true)
            {
                Image<Bgr, byte> gambar = new Image<Bgr,byte>(openPic.FileName);
                originalImage.Source = Emgu.CV.WPF.BitmapSourceConvert.ToBitmapSource(gambar);
 
                Image<Bgr,byte> bunder = detectCircle(gambar);
              lingkaranImage.Source = Emgu.CV.WPF.BitmapSourceConvert.ToBitmapSource(bunder);
 
                Image<Bgr, byte> kotak = detectRectTri(gambar);
                kotakSegitigaImage.Source = Emgu.CV.WPF.BitmapSourceConvert.ToBitmapSource(kotak);
            }
 
        }

Then below was the result:

References: 1

First WPF Application with EmguCV

Actually I have experienced working with Open CV 2.3 and Visual Studio 2010 while doing my thesis for my undergraduate study, I also wrote some tutorial, but I lost the articles because someone destroyed my website haha anyhow, after 5 years, I started my master degree and somehow get stuck with vision again. But this time, I tried to write something in C#, and openCV cannot afford that, so I use EmguCV as a C# wrapper of OpenCV library. This is just beginning, I hope the rest of my journey would be easy haha

My Weapons:

  • Visual Studio 2015 Express
  • Windows 10 Education
  • Kinect Camera V2

Preparation:

  • EmguCV 3.1.0 , as per this date, this is the newest version. Follow the instruction in the website. Basically, the newer version was easy to install. They provided .exe file to be executed.
  • After finished, building the Emgu.CV.Example.sln from the installation folder (this is also could be found in the website). This step is for retrieving related library that will be used for program development. Just give some note to change the Build Properties into x64 machine. I got many errors and exception because of this. Right Click in the solution file then click Properties.

  • Now, you must have seen Emgu.CV.UI.dll , Emgu.CV.World.dll , etc in the bin folder. For now, it’s enough.

Building My First WPF Application using EmguCV

My first application is how to load an image from our computer, then convert the image into Gray Image. I have been reading many tutorials and done some troubleshooting also. I spent one whole day to troubleshooting until this program works. ūüôĀ

  • Create New WPF Application Project with Visual Studio
  • Take care of the reference library first. Add following library/ files into the project: Emgu.CV.UI, Emgu.CV.World. Emgu.Util (For the main references) and Add following existing files: opencv_core220.dll, opencv_imgproc_core220.dll, opencv_ffmpeg310_64.dll. Other than Emgu.CV.UI and Emgu.CV.World, I could not find it in the installation folder of Emgu. So I add it, and copy from example solution and paste it into my project folder.
  • Add BitmapCourseConverter.cs class from Emgu WPF folder in the installation folder. This is as converter, because WPF and Windows Form works differently. WPF uses System.Windows.Media.Imaging while Windows Form uses System.Drawing. Emgu and OpenCV were supposed to work with unmanaged code.
  • Make the simple WPF interface with Image container and Button.
<Grid>
  <Grid.ColumnDefinitions>
   <ColumnDefinition />
   <ColumnDefinition />
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
   <RowDefinition Height="*"/>
   <RowDefinition Height="auto"/>
  </Grid.RowDefinitions>
 <Image x:Name="myImage" Margin="5" />
 <Image Grid.Column="1" x:Name="myGreyImage" Margin="5"/>
 <Button Grid.Column="1" Grid.Row="1" x:Name="testButton" Content="Load Image" Click="testButton_Click" HorizontalAlignment="Right" VerticalAlignment="Bottom" Height="44" Width="92"/>
</Grid>
  • Insert the code into the Button Event Handler
OpenFileDialog openPic = new OpenFileDialog();
            if (openPic.ShowDialog() == true)
            {
                Image<Bgr, byte> gambar = new Image<Bgr, byte>(openPic.FileName);
                myImage.Source = Emgu.CV.WPF.BitmapSourceConvert.ToBitmapSource(gambar);
 
                Image<Gray, byte> gambarAbu = gambar.Convert<Gray, byte>();
                myGreyImage.Source = Emgu.CV.WPF.BitmapSourceConvert.ToBitmapSource(gambarAbu);
 
            }

Result


If you still found error, refer to any other references: 1 | 2 |

A Journey to Japan – Day 6: Hakata, Fukuoka

Hari ke 6 merupakan hari yang cukup singkat, karena habis diatas shinkansen. Lagi-lagi tim terbagi 2, ada yang ingin berkeliling Osaka, salah satunya ke Osaka Temple, lalu Universal Studio. Sisanya ingin ke Hakata, mengunjungi HKT48 Theater. Keduanya merupakan tujuan yang menggiurkan. Akan tetapi, kembali ke tujuan awal, yaitu mengelilingi theater 48, maka saya ikut tim kedua, yaitu naik shinkansen menuju Hakata, Fukuoka.

Karena kita berangkat dari Osaka, maka jarak menuju Fukuoka tidak terlalu jauh, kurang lebih 3 jam. Ada yang unik dari perjalanan kali ini. Kita pulang dari Fukuoka malam harinya menggunakan bullet train yang seharusnya tidak bisa dinaiki menggunakan JR Pass. Karena kereta ini jenis yang berbeda dan merupakan yang tercepat dibanding kereta cepat lainnya. Namanya Nozomi. Entahlah kenapa kita diperbolehkan naik kereta itu haha Karena itu, kita bisa sampai kembali ke Osaka lebih cepat dari seharusnya.

Baiklah, kembali ke perjalanan di Hakata. Pertama kali turun di stasiun Hakata, rasanya sangat berbeda dengan kota Tokyo maupun Osaka. Hakata terasa lebih pedesaan, udaranya segar karena dekat laut, ketika turun, bau laut langsung tercium. Lingkungannya asri. Penduduknya pun berbeda, terlihat lebih sederhana, kebetulan setibanya disana, terlihat banyak murid sekolah sedang dalam perjalanan pulang.

Theater HKT48
Berada di sebuah Mall, Hawks Town Mall. Sangat mudah ditemukan. Bentuk dari HKT48 theater ini memiliki ciri khasnya sendiri pula. Menurut saya, layoutnya sangat mewah dibanding theater 48 grup lainnya. Bentuknya seperti catwalk.
Berhubung hari itu kita tidak berencana untuk menonton pertunjukan, kita pun tidak memiliki tiket theaternya, sehingga kita hanya menonton dari Layar In Focus di lobi theater. Walaupun begitu, lobinya sangat nyaman, layar yang cukup besar, sound system yang live dikeluarkan dari dalam theater beserta kursi untuk para penonton. Yahhh, untuk pertunjukan tidak perlu bayar, itu sudah sangat cukup lah ya. Lalu di lobi theater ada HKT48 shop kecil yang menjual merchandise para member HKT48.

hkt48_2

Pokemon Center
Agak sedikit flashback ke pagi hari. Sebelum berangkat ke Hakata. Kami semua menyempatkan diri mampir ke Pokemon Center. Karena konon katanya, tempat ini hanya ada di Osaka, Pokemon Center terbesar. Letaknya didalam Mall, tapi lupa nama Mall-nya apa.
Didalam dijual merchandise-merchandise pokemon. Banyak jenisnya, dari yang paling murah hingga yang sangat mahal. Selain itu, ada semacam game booth Pokemon. Disini para Pokemon Master dapat menambah poin miliknya, dengan pertarungan sepertinya. Ntahlah, hanya menonton saja hehe

pokemon center

Expenses:

  • Lunch at McD – 200 yen
  • Subway at Fukuoka – 600 yen
  • Pokemon Center – 600 yen

TOTAL 1400 yen = ~ IDR 140.000

iPhone-graphy: Application

Karena tertunda cukup lama, akhirnya bisa meneruskan bagian kedua dari artikel tentang iPhonegraphy. Part 1, telah dibahas mengenai perangkat-perangkat tambahan apa saja yang tersedia untuk meningkatkan kemampuan kamera iPhone anda. Kali ini, saya akan berbagi, aplikasi-aplikasi apa saja yang ter-install pada iPhone saya yang dapat meningkatkan gambar yang telah diambil dari kamera standar. Ada 4 aplikasi yang sering saya pakai dalam mengolah foto di iPhone.

01. Camera+

Aplikasi third-party ini sangat membantu sekali dalam mengambil gambar. Kelebihannya dibanding kamera standar adalah pada Camera+, kita dapat mengatur titik fokus dan juga titik exposure secara manual. Dengan bantuan titik exposure tersebut, kita dapat menentukan daerah-daerah untuk meletakkan titik cahaya. Sangat membantu ketika objek berada di posisi tidak kena cahaya, kita dapat memanipulasi letak cahaya tersebut, sehingga akan lebih terang dari objek aslinya.

Photo Jul 15, 12 16 47 AM

Kelebihan selanjutnya adalah dapat secara langsung memberikan filter, seperti pada Instagram. Bedanya adalah ada preset-preset yang siap pakai, yang sudah diatur sesuai tema, misal tema Food, Scenery, Beach, Concert, Sunset dan lain sebagainya. Lalu, mengatur clarity suatu gambar agar lebih tajam, ini merupakan fitur favorit daripada Camera+ ini. Fungsi standar editing lainnya pun ada, seperti crop, brightness contrast, temperature, saturation, blur dan masih banyak lagi.

02. Snapseed

Aplikasi ini dulunya berbayar, namun setelah diakuisisi Google, aplikasi ini menjadi gratis. Aplikasi ini sangat powerfull, seperti Adobe Photoshop versi Lite untuk Mobile device. Fitur lainnya adalah menu HDR untuk semakin mempertajam gambar landscape anda, Lalu dapat pula menambahkan tekstur vintage atau drama.

Photo Jul 15, 12 18 04 AM

03. Line Camera

Aplikasi yang sangat simpel dan gratis ini sangat berguna ketika anda ingin membuat sebuah kolase dari beberapa gambar. Biasanya sebelum posting di Instagram atau media sosial, ada banyak momen yang ingin disusun menjadi sebuah kolase. Aplikasi ini merupakan aplikasi yang tepat. Terdiri minimal 2 sampai 8 gambar dapat dibuat kolase dengan aplikasi ini. Yang menjadi kelebihan Line Camera adalah fitur tambahan yang tidak didapatkan dari aplikasi kolase lainnya, seperti mengubah warna, mengubah bentuk partisi kolase, mengubah warna dan beberapa properti lainnya.

04. Label Box

Aplikasi ini berfungsi sebagai pengganti watermark. Jika kurang puas dengan bentuk text biasa, atau tidak memiliki gambar watermark sendiri, kita dapat menggunakan Label Box untuk mempercepat memberikan signature pada gambar kita. Jika sudah memiliki gambar watermark sendiri, bisa menggunakan aplikasi Ezy Watermark.

Pertemuan Yang Tidak Direncanakan

Kali ini saya akan sedikit bercerita mengenai pengalaman handshake 18 Mei lalu, pasca pengumuman senbatsu single ke-6 JKT48. Karena keterbatasan waktu, memang belum sempat mendokumentasikan apa yang terjadi saat itu -,-” Bahkan sempat terpikir untuk tidak menulisnya sama sekali, karena memang bukan pengalaman handshake yang menarik haha Namun, berhubung, sebentar lagi semua ini akan berakhir dan menjadi serpihan kenangan, rasanya cukup bijaksana jika tetap menuliskan dan mungkin berguna kemudian kelak xD Let’s start…

Maret 2014 hingga April 2014 merupakan momen yang cukup krusial untuk para member JKT48 dan juga fans-nya. Yaitu memilih senbatsu suatu single oleh fans. Hanya 16 member yang akan terpilih, dipilih oleh fans, menggunakan sistem voting. Singkatnya, fans dengan dana besar, chance-nya untuk meng-gol-kan member ke 16 besar bertambah besar.

Read more