OpenCV – Select, Capture And Save Camera Feed

EyeLine Video Surveillance Software

This Video Shows how to Capture and save the camera feed using OpenCV. It also Details how to select different cameras.

As always, To compare your scripts, if you have issues, I have included notes and the completed scripts at the bottom of the page which you can view or download from my Google Drive. The scripts also have notes as comments which appear after a #.

Remember if you can’t view fullscreen, you can right click the ‘youtube’ icon in the bottom right and select ‘view on Youtube.com’

Notes

The supplementary information can be found on the official OpenCV website https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html

The # is used in python to comment code after it on the same line. The importance of using this to comment code is the compiler ignores this when running the code but anyone coming later to work with your code can see why you have used the code you have or any notes you may have put in to modify it.

Some people say that “””comments””” is ok for multi line comments but this is wrong as it can get you into trouble. This is because it is a ‘docstring’ which is treated slightly differently. more info on ‘docstrings’ and their rules can be found here https://www.python.org/dev/peps/pep-0257/ but it is a slightly more advanced topic that you should save for later. Just remember only use a ‘#’ for comments on each line.

Download Links

Github OpenCV repository https://github.com/opencv/opencv/

Completed Scripts

Below is the link to the Google Drive repository for this lesson. You can either view online or download.

https://drive.google.com/drive/folders/190fHm-aJZfLM41rWjFPHxJycKteIq5zW?usp=sharing

OpenCV – Read and Write Images

Xara Web Designer

This Video Shows how to Open, Read and Write images using OpenCV. In the last post, I mentioned he flicks back to using Pycharm IDE for code editing so definitely go to https://www.jetbrains.com/pycharm/ and download / install the pycharm IDE which at present is free in community edition.

To compare your scripts, if you have issues, I have included notes and the completed scripts at the bottom of the page which you can view or download from my Google Drive.

Remember if you can’t view fullscreen, you can right click the ‘youtube’ icon in the bottom right and select ‘view on Youtube.com’

Notes

When copying lena.jpg, depending how your file structure has formed, when running the script, you may get an error. Try right clicking on the ‘venv’ folder and copy the image there or drag and drop from the main folder location. The script should now run and display the ‘lena.jpg’ image.

Keyboard key values can be found at http://www.asciitable.com/. It looks like below. Use the key ‘DEC’ column value. The key description is in red in the last column.

Ascii Table
http://www.asciitable.com

Download Links

You can download Pycharm from https://www.jetbrains.com/pycharm/

You do not need to but if you want to download microsofts awesome free code editor Visual Studio Code, This is the link https://code.visualstudio.com/ but all of the lessons are completed in Pycharm which I would advise using to follow along and then convert to VS code later when you are experienced.

Github OpenCV repository https://github.com/opencv/opencv/

Completed Scripts

So I hit another WordPress file type issue and can’t share script files so below is the link to the Google Drive repository for this lesson. You can either view online or download.

https://drive.google.com/drive/folders/190fHm-aJZfLM41rWjFPHxJycKteIq5zW?usp=sharing

Opening Downloaded Files

Sometimes your browser will not allow you to open downloaded files from the bottom of the browser, especialy if they are .zip files but you can either use the drop down arrow next to the downloaded file at the bottom of your browser and select ‘open in explorer’ or go to your ‘Downloads’ folder and find it there. Again if it is a .zip file then you can right click it and select ‘Extract All’ which will create a larger size folder version of the zip file. This will work now.

OpenCV – Installing on Windows

Xara Web Designer

If you are using a Windows Operating system i.e. Windows 10 then this is the video showing you how to install OpenCV which is crucial to learning. If however you are using a Linux Ubuntu system then please look at this video https://youtu.be/cGmGOi2kkJ4

The topics covered in this video are also useful for learning background features in Windows 10.

Please see the links and text below to follow along.

Download Links

You can download Python from https://www.python.org/

You do not need to but if you want to download microsofts awesome free code editor Visual Studio Code, This is the link but the rest of the lessons are completed in Pycharm which I would advise using to follow along and then convert to VS code later when you are experienced. https://code.visualstudio.com/

Commands for command prompt

  • python –version
  • pip –version
  • pip install opencv-python
  • python
  • import cv2
  • cv2.__version__

Opening Downloaded Files

Sometimes your browser will not allow you to open downloaded files from the bottom of the browser, especialy if they are .zip files but you can either use the drop down arrow next to the downloaded file at the bottom of your browser and select ‘open in explorer’ or go to your ‘Downloads’ folder and find it there. Again if it is a .zip file then you can right click it and select ‘Extract All’ which will create a larger size folder version of the zip file. This will work now.

Command Prompt

Windows 10 is what they call ‘evergreen’ which in laymans terms means it is always updating and changing. This is normally behind the scenes stuff but does affect how the menus work. At the time of writing, to get the command prompt in the method shown on the video, you have to

  • Right Click the Windows Icon (Menu Icon)
  • Select ‘Run’
  • Type ‘cmd’ in the box
  • click ‘OK’ or press ‘Enter’

OpenCV – Introduction

Xara Web Designer

OpenCV is all about processing Images from still photography or film and converting the data in the images to computer code and gives you the ability to work with the raw image data.

Thats a big piece to get your head around but I have found this set of youtube learning videos that starts at the basics of how computers see images and takes you through it in bite size pieces up to the capability of reading lane marking for self driving vehicles. I am also adding notes and supplementary notes after the videos to help understand as this site is geared towards knowing nothing and taking through to being capable yourself without needing to attend college. I myself am self taught on most things with the guidance and material provided by others on the internet or libraries. The downside is that you do not have a piece of paper for a job interview but you will have demonstrable skills so stick with it as you can learn anything.

The you tube video below gives a good introduction to OpenCV and how computers see images. It also includes an brief introduction to ‘numpy’ which is a highly optimised set of Python objects for working with images and numbers.

Please see the links and text below to follow along.

If you have never coded with Python and don’t quite follow along then please have a look at the following tutorial but if you just stick it out, you will pick it up. Think of coding like when you learnt to drive or ride a bike, scary at first but second nature after a while.

youtube – freecodecamp.org learn python in 4.5 hours

TEXT EXTRACTION WITH FreeOCR

Optical Character Recognition software has been around for a while now and is used in many applications from number plate recognition to document scan to text. The big opportunity comes when incorporated into Surveying and robotics. For this, many companies turn to big Cloud Computing Products such as Google Cloud or Azure but there is a cheaper way if you are prepared to do some computer legwork and are not after a one stop shop solution. If you want one stop then GCP or Azure is the place to go but you will pay for it.

Rescue deleted files or photos - O&O DiskRecovery

Alternatively you can combine smaller products as below to achieve similar great results for efficiency in mass processing. I have remained generic and not to mention brands as either the open source or proprietry products will return good results.

The big hold up has been getting GOOD free opensource/freeware OCR software. We now have it in the form of FreeOCR downloadable from paperfile http://www.paperfile.net.

FreeOCRIcon

This software allows you to scan all documents into word format extracting the text automatically and works with pictures too. It uses the tesseract OCR engine which is at the following GitHub page http://code.google.com/p/tesseract-ocr/ and can be compiled into your own software creation for the aspiring coders amongst us.

Lets say you want to scan CCTV footage for registrations of people coming and going through a gate, Simply turn the video into images (maybe using VLC) and load the saved images into FreeOCR. Hit the OCR button and it will convert any text in the images to a text file.

This might be a good idea for automated scanning of CCTV footage after a crime to find witnesses.

Another alternative use would be for BIM and scanning asset tags or data plates. Lets say you have some georeferenced images taken with something like a SPECTRA SP20 you would be able to cross refer the OCR recovered Model and Serial number with the GeoTag in the images Metadata in an automated way to geolocate the asset data in the database.

You would already have to have an asset database to query but  you could add assets like this too.

Maybe you could automate cheaply using a GoPro Hero5 (or later) set to Linear or Medium Field Of View, 50 Frames Per second and good forward lighting. You would also need a piece of software that uses tesseract and will record the frame or picture number against the OCR output and image metadata including GPS data.I mention this method with a GoPro example as you could use the same video footage as you take for photogrammetric modelling where the results would improve with the better camera and also records the Geolocation. If you need a GoPro, they now supply the Hero7 12MP on Amazon. Click the image below to see the listing and the Specs.

This Photogrammetric modelling would provide the basis for the 3D virtualised world engine for self operated robots later.

Now Moving on from data collection, imagine if robots could read languages and understand, orientate and operate themselves with OCR or feature extraction with 360 cameras, then we are talking that we are close to robots automated operations in changing environments.

Now lets combine other work with driverless cars and the virtualised world engine, we are talking about fully autonomous vehicles or self operated machines in a variable world.

The helps the Future to be Exciting as we change how we apply current technologies to deliver futuristic capabilities today.

Insta360 Air (Micro USB) 360 Camera

Mapping Underground Assets

The vivax metrotech system for mapping underground assets like pipework and cable runs with a relatively high accuracy.

The equipment that has inspired this idea is the VIVAX METROTECH vSCAN range which can be viewed here. https://www.vivax-metrotech.com/

Like many utility detectors, It locates wires and buried metalic objects but what is so great about the direction of this product range is that it can combine with locating a sewer Inspection camera head which brings the ability to reality capture, with photogrammetry, inside of pipework or cable runs. Not the best result as it is only in one direction but there is nothing stopping this being developed into fore and aft cameras.

To do this, you send the vCamMX camera up the pipe or chamber  which records all the image data while someone walks above the ground with the vLocCam2 Locator. This will provide the depth relative to the locator which records it geolocation.

It is also handy to be able to Geolocate all detected power lines and utility services like CATV, telephone and pipework over 50mm. I think thats a safe bet as the diameter of the smaller head is 18mm so might be able to be used in smaller bores to confirm the laying of a water pipe for instance but the manufacturer states 50mm.

There really is not much to say about this process as it is just amalgamating a current CCTV of sewers process with an upgraded utility detector with GPS but it is more the tool that makes it easy to process the data in an automated fashion.

Having said that, with the potential to 3D model the video, it can also aid non destructive computer based testing and defect detection of underground utility services.

The geolocation aspect of this also provides a way to satisfy much of the financial risk of PAS256 and the geographic linking between non-infrastructure assets.

 

NAVVIS M6 MOBILE REALITY CAPTURE

The Terestrial Scanning scene has been dominated by static Laserscanners or heavy post processing of photogrammetric data. Now there is another way:-

The all-in-one indoor reality capture mobile mapping system – NavVis M6

Once set up, all you have to do is push it along and let it scan continuously. Now you no longer have to plan your static scan positions for line of sight, just push it round all objects and the job is done. No more worrying if you had the line of site on that object.

It claims and is foreseeable to be able to:-

  • Scan up to 30x faster than with stationary scanners and devices
  • Capture up to 30,000 square meters per day
  • Adapt to complex indoor environments while continuously scanning

These are bold claims but it just looks so easy.

I do see an issue, being devils advocate, is crossing voids and industrial process floorings. It sure will be able to traverse workshops, warehouses, Hangars and offices but when it comes to Stairs and crossing voids, I am sure some kind of work-around will need to be envisaged. Otherwise it really looks like a game changer for Reality Capture.

Their Brochure is below but for further Information please visit their website www.navvis.com/m6