Filming long videos with the Raspberry Pi camera

I’ve been interested in trying to use the Raspberry Pi to film really long videos which can last for several days. If you set the time flag (-t) for raspivid to 0, then the camera will record until you kill the program. The command is below; note that I’m only filming at 10 frames per second and that the “-n” flag cancels video preview:


raspivid -n -fps 10 -t 0 -o $temp

Read More
First impression of Swift (Apple’s new programming language)

Swift is Apple’s new programming language, which promises to allow you to write iOS and OS X apps more easily than with Objective-C. Apple have released a free eBook titled “The Swift Programming Language” which provides an overview of the language. This is where I gained my main impressions on Swift. To give you a little background on myself: while I have had an interest in getting into app development for a while, at this point I haven’t touched any Objective-C – I am currently programming mainly with C, C++ and Python.

The first thing I thought when I started looking at the Swift code examples, is how much it reminds me of Python. Consider the first Python script most of us learned:

Read More
What I learned while learning C++

C++ is regarded by many as one of the most difficult programming languages to become proficient in. After spending the past couple of months learning and writing a lot of C++ I am positive that while I quite like the language, it is definitely not a good first language for someone just starting out. There’s a reason a lot of first year computer science courses lean towards teaching Python and Java, leaving C++ for later, when students have a good grip on the fundamentals of programming.

One of the things I’ve discovered since I started learning C++ by myself online, is that there are many, many websites out there with tutorials and guides to the language. They looked professionally done and I was happy to use them. However, after I wrote my first tutorial on the C++ language and asked others for feedback on reddit, it was pointed out to me that a lot of C++ resources online can be misleading to learners. I’m not sure if its due to the complexity of the language or the authors’ of such tutorials wanting to keep things simple, but the result is a lot of tutorials online encourage bad practice, and even code that is not compliant with the C++11 standard.

Read More
C++ for beginners

In this tutorial, I’m going to provide an introduction to the basics of the programming language C++. I’ll describe how to compile your first program with the gcc compiler on Linux and Mac, although the code should also work on Windows using the Visual Studio compiler. If you’re new to programming, I’d probably recommend getting started with an easier scripting language like Python, before you get into C++. That said, hopefully the information in this post should still be useful for the complete beginner.

What is C++?
C++ was invented by Bjarne Stroustrup in 1978 as an extension of the popular C programming language. It added classes and the ability to write object orientated code.

Is C++ worth learning?
Although C and C++ came out decades ago, they remain extremely popular when speed and performance are a crucial requirement. Although C is a great language, C++ added a lot of functionality which comes in handy for big projects. While knowing C will give you a head-start when understanding C++, it is not essential. Personally, I started off learning C before changing to C++ because the imaging library I use for a lot of my work (OpenCV) is written in C++.

Read More
Find sequence descriptions with BioPython

Image you have a lot of nucleotide sequence identifiers and want to find out what organism the DNA is from. You could go to the NCBI website and spend a long time finding out, or you could write a short Python script using BioPython to find out the headers from each fasta file the identifier refers to:

Read More
Python Regular Expressions

Before today, the only real use I’d had for regular expressions in Python was to just find the first instance of a pattern. For example, if I want to find the contents of the text between the first set of single quotation marks (in this case ‘26245730’), I would proceed like so:

import re

all_id="'26245730': 817, '389595538': 735, '541129065': 529, '541129071': 340, '558870185': 305, '444325280': 287, '573974252': 272, '281314044': 222"

first_id = re.search("'(.*?)'",all_id)
print first_id.group(1)

The arguments passed to re.search define the pattern I am looking for: The single quotation marks on either side of the brackets show that I am looking for a pattern between them. The “.” within the brackets tells Python that I am happy with finding any character, number, etc and the “*” next to these mean it will look for 0 or more instances of this text. Finally, the “?” ensures that the expression isn’t greedy. What does it mean to be greedy with a regular expression? It means that instead of finding the pattern between the first two single quotation marks, it will find the pattern between the first and the last quotation marks! So I’ll end up with practically all of my string being returned!

Read More
Where to learn C++

C++ is the most recent language I’ve acquired, and while I certainly still have a lot to learn, I’ve gained a reasonable understanding from the following free resources online:

  1. LearnCpp.com – Learn C++
  2. tutorialspoint – The C++ Programming Language
  3. cplusplus.com – C++ Language
  4. XoaX.net – C++ Video Tutorials
  5. Google Developers – C++ Class
  6. Cprogramming.com – Programming Tutorials – C, C++, OpenGL, STL
  7. University of Southern Queensland – Object oriented programming in C++
  8. Stephan T Lavavej – Core C++
  9. Professor Peter Sommerlad – Modern and Lucid C++ for Professional Programmers
  10. Software Design Using C++

**UPDATE**

I was recently alerted to the fact that some of these resources can contain incorrect information/bad practices. Here’s a great list of C++ resources which have been vetted by the reddit learnprogramming community. One recommended resource is a book titled “C++ Primer 5th edition”. It was published in 2012 so it covers the C++11 standard.

Read More
Best resources for learning OpenCV (Python and C++)

Here’s a list of some of the websites, books and videos (for both Python and C++), that I have found very useful while learning OpenCV.

Python

  1. Using OpenCV with Python and ROS (Video) – Great introduction to computer vision and OpenCV.
  2. PyImageSearch – Website has a lot of great tutorials on many different applications of OpenCV.
  3. OpenCV-Python Tutorials (Website) – Official Python documentation and tutorials.
  4. OpenCV-Python Tutorials (Website) – Comprehensive set of tutorials.
  5. OpenCV Python (Website) – The original Python tutorials I started with, most of these have been ported to the website above.
  6. OpenCV 3 With Python (Website) – Great list of Python tutorials.
  7. Tentative NumPy Tutorial (Website) – As OpenCV reads images into NumPy arrays, its useful to have an understanding of this library.
  8. Python – Getting started with OpenCV (Website) – Introduction to using Python with OpenCV.
  9. Programming Computer Vision with Python (Book) – How to use Python to build computer vision programs.
  10. OpenCV Computer Vision with Python (Book) – Short book on getting started with OpenCV and Python.
  11. Building an image processing pipeline with Python (Video) – Talk about how Python and OpenCV are used in industry.
Read More
Using C++ or Python for OpenCV Programs

When I first started learning OpenCV, I was working exclusively with Python. While I am still a huge fan of the language, today all of my OpenCV programs are written in C++. Why?

  1. Some of the deeper functionality of OpenCV has not been completely ported to Python (although hopefully the release of OpenCV 3.0 will fix most of these issues).
  2. Most in-depth textbooks on image processing and computer vision that cover OpenCV use C++ as their primary language. It was therefore easier to learn from these resources by adopting the language.
  3. A lot of the computer vision techniques I use (SIFT, machine learning, etc), are better documented in C++.
  4. Passing images back and forth between NumPy arrays has overhead that C++ doesn’t have to worry about.
  5. As has been suggested to me by Carl Bell, Python struggles to perform well with overloaded functions.
Read More
Are university lectures still relevant?

Lately, there’s been quite a few articles (such as here and here) discussing the use of the university lecture and its perceived shortcomings. The question is asked: is the lecture an unengaging relic from before the digital age? Are lectures really the best way to learn? I attended many lectures throughout my undergraduate studies, and have also tried out massive open online courses (MOOCs) from providers such as Coursera. To be perfectly honest, I don’t mind lectures at all. While they could be dull at times, they had the advantage of sitting you in a room where information was being fed to you whilst you were (mostly) shielded from the distractions of the outside world. Having a timetable of lectures was a powerful way to organise your learning (especially as you were paying for this education). It takes a lot of motivation to sit through a fraction of the lectures each week from online courses.

Read More