C++ Archive

C# adding reference error – Checking a C++ DLL is valid for a C# project

DLLs compatible with C# projects can either be managed or unmanaged. However, if they’re unmanaged, they cannot be included in the project using the standard References->Add Reference->Browse->OK method, as only managed DLLs can be added in .net applications in this method. To add unmanaged DLLs you need to use a form of DLLImport, which I

How to install OpenCV – Windows machines

Since 2012 when I first conducted an OpenCV project as part of my Bachelor’s dissertation at Keele, I have ended up having to install OpenCV about 4 times on various computers. Today is yet another occasion where the need for an installation of OpenCV has been necessitated but, because of the length of time between

Calculating a log normal value from an average and standard deviation

It’s been a bit quiet round here recently due to project work at the office primarily with little Grasshopper work and little in the way of interesting snippets. However, one which I’ve decided to put here for future use is a function to calculate a log normal value from a given average and a given

How to fix the ‘Common Language Runtime was unable to set the breakpoint’ error in Visual Studio projects

When you have multiple projects which link together, it can be handy to have them open in Visual Studio to debug through or work on them. This is especially true if you’re using libraries which contain common code across projects. That is the purpose of a DLL after all (or static library), to provide common

How to convert OpenCV cv::mat to System Bitmap to System ImageSource

OpenCV is an open source computer vision library which can be used for a wide variety of things such as face recognition, people detection, motion tracking, video editing and image manipulation. For my undergraduate project, I made use of the OpenCV libraries to create a facial recognition system. It used a webcam to detect ID

C++ Error LNK2005 – item already defined in file.obj

Linker errors (LNK) can be a bit more difficult to solve than standard C errors if you don’t know how to read the error output. This is added to by the fact that you can’t double-click the error and be taken to the line causing the problem (if using Visual Studio anyway), so being able

Interpolating data points to produce colour maps – code examples

For a lot of the work I do in my research, I need to produce colour maps which can visualise data in a user-friendly way while still getting across the necessary elements of the analysis performed. In my current area of research, looking at wayfinding tools to analyse healthcare building design for natural wayfinding, I’m

Obtaining the angle between two vectors for 360 degrees

This previous post demonstrated how to obtain the angle between two vectors from three geometric points, providing an angle between 0-180 degrees. However, there may be times when you need the angle between 0-360 degrees instead, as I did earlier this week. As such, this post aims to complete the previous with the solution for

Calculating angle between two vectors from geometric points – code solution

Calculating the angle between two vectors is a fairly easy solution to find online – there are plenty of maths help websites which will take you through step by step how to work out the angle, however, not many sites will provide you with the necessary programming code to put this into your software. As

For loops – running method calls in the declaration

For loops are a key part of recursive code, allowing us to iterate over items in a vector, or perform actions a set number of times without repeating the lines of code. We all know how they can be applied and declared, however, something which may not be very well-known is the ability to call