Advice to Diabetics

Rujuta Diwekar is the highest paid dietician in India. She is the one who took care of junior Ambani to lose 108 kgs.

Her advice to diabetics:

1. Eat fruits grown locally ….. Banana, Grapes, Chikoo, Mangoes. All fruits have FRUCTOSE so it doesn’t matter that you are eating a mango over an Apple. A Mango comes from Konkan and Apple from Kashmir. So Mango is more local to you.

Eat all the above fruits in DIABETES as the FRUCTOSE will eventually manage your SUGAR

  2. Choose Seed oils than Veggie oils. Like choose ground nut, mustard, coconut & til. Don’t choose chakachak packing oils, like olive,  rice bran etc
Go for kachchi ghani oils than refined oils

  3. Rujuta spends max time in her talks talking about GHEE and its benefits.
Eat GHEE daily. How much GHEE we should eat depends on food. Few foods need more GHEE then eat more and vice versa. Eat ample GHEE. It REDUCES cholesterol.

  4. Include COCONUT. Either scraped coconut over food like poha, khandvi or chutney with idli and dosa
Coconut has ZERO CHOLESTEROL and it makes your WAIST SLIM

  5. Don’t eat oats, cereals for breakfast. They are packaged food and we don’t need them.  Also they are tasteless and boring and our day shouldn’t start with boring stuff.
Breakfast should be poha, upma, idli, dosa, paratha

  6. Farhaan Akhtar’s New ad of biscuits – fibre in every bite… Even ghar ka kachara has fibre, likewise oats have fibre. Don’t chose them for fibre. Instead of oats, eat poha, upma, idli, dosa

  7. No JUICES till you have teeth in your mouth to chew veggies and fruits

  8. SUGARCANE is the real DETOX . Drink the juice fresh or eat the SUGARCANE

  9. For pcos, thyroid – do strength training and weight training and avoid all packaged food

10. RICE – eat regular WHITE RICE. NO NEED of Brown rice. Brown rice needs 5-6 whistles to cook and when it tires your pressure cooker, then why do you want to tire your tummy.

A white rice is hand pounded simple rice

Rice is not high is GI INDEX.  Rice has mediun GI index and by eating it with daal / dahi / kadhi we bring its GI index further down
If we take ghee over this daal chawal then the GI INDEX is brought further down.
B. Rice has some rich minerals and you can eat it even three times a day

11. How much should we eat – eat more if you are more hungry, let your stomach be your guide and vice versa

12. We can eat rice and chapati together or only rice if you wish. It depends on your hunger. Eat RICE in ALL THREE MEALS without any fear.

13. Food shouldn’t make you scared like eating rice and ghee. Food should make you FEEL GOOD

14. NEVER look at CALORIES. Look at NUTRIENTS

15. No bread, biscuits, cakes, pizza, pasta

16. Ask yourself is this the food my Nani & Dadi ate?  If yes then eat without fear.

17. Eat as per your season. Eat pakoda, fafda, jalebi in monsoon. Your hunger is as per season. Few seasons we need fried food so eat them.

18. When not to have chai – tea – don’t drink tea as the first thing in morning or when you are hungry. Rest you can have it 2-3 times a day …

Advertisements

Three 1/2 minutes

For those who get up at night from sleep to urinate or early in the morning.*

Each individual must take note of the three 1/2 minutes.

Why is it important? Three 1/2 minutes will greatly reduce the number of sudden deaths.

Often this occurs: a person who still looks healthy has died in the night.

Often we hear stories of people who say, “Yesterday, I was chatting with him. Why did he suddenly die?

The reason is that when you wake up at night to go to the bathroom, it is often done in a rush.

Immediately we stand, and the brain lacks blood flow.

Why are “Three 1/2 minutes” very important?
In the middle of the night, when you are awakened by the urge to urinate for example, the ECG pattern can change.

Because in getting up suddenly, the brain will be anemic and causes heart failure due to lack of blood.

You are advised to practice the “Three 1/2 minutes,”
which are:
1. When waking from sleep, lie in bed for the 1st 1/2 minute;
2. Sit in bed for the next 1/2 minute;
3. Lower your legs, sitting on the edge of the bed for the last half-minute.

After three 1/2 minutes, you will not have anemic brain and heart will not fail, reducing the possibility of a fall and sudden death.

The 10th apple effect

A hunter once lost his way deep inside the jungle while chasing a deer.
He used all his navigation skills but neither did he find any way out of the jungle, nor could he find any food to eat for 8 days at a stretch.
He started feeling so damn hungry that he could eat an entire elephant at one go.
Disappointed, he lost all hope. And that is exactly when an apple tree caught his sight.
He collected a dozen apples to feed him for the rest of his search.

As he ate the 1st apple, his joy knew no bounds and he just couldn’t stop feeling grateful and blessed.
He thanked life.
He thanked God.
He could not believe his luck when he ate the 1st apple, but he was less grateful while having the 2nd apple and even lesser grateful when he had the 5th apple.

Somehow, with each passing apple, the hunger still kept on increasing and the joy kept on reducing drastically.
He just could not enjoy the 10th apple.

Why?
He had already taken for granted the gift of having found an apple tree in the middle of a forest after 8 long days of wandering with hunger !!
When he took the 10th apple in his hand, he was still very hungry but he just did not feel like having it any more.
Economics calls this diminishing marginal utility…I would like to call it diminishing gratitude…
in simple words, taking things for granted !!
Or let’s just call it the 10th apple effect.

The 10th apple did not lack taste, it did not lack the potential to satisfy his hunger but the only thing lacking was his gratitude for finding food in the middle of the jungle.

The hunter represents us.
And the apple represents the gifts that life gives us.
The 10th apple represents our lack of gratitude for these gifts of life and our ‘take everything for granted’ attitude.

As we continue receiving the gifts of life, our hunger, our greed keeps on increasing and the joy we get from these gifts diminishes.

The 10th apple is as sweet as the first apple.
If the 10th apple fails to give you as much pleasure as the first one, nothing is wrong with the apple, everything is wrong with you !!
If you get bored on a dull day, it is not because the day is dull and boring. It is because your gratitude has become dull and boring.

The gift of life for another day cannot be taken for granted.

The Nth year of life, should seem as exciting as, the 16th year, as the 25th year, as the 50th year….

Never let the ‘10th apple effect’ make you take these gifts of life for granted.
Never let your gratitude for life fade away.

Setting up Machine Learning workstation

NVidia 1060
sudo add-apt-repository ppa:graphics-drivers
sudo apt-get update
sudo apt-get install nvidia-384
sudo apt-get install nvidia-367
sudo apt-get install nvidia-smi

dcml@sun:~$ lsmod | grep -i nvidia
nvidia_uvm            671744  0
nvidia_drm             45056  1
nvidia_modeset        843776  5 nvidia_drm
nvidia              13119488  268 nvidia_modeset,nvidia_uvm
drm_kms_helper        151552  2 i915,nvidia_drm
drm                   352256  5 i915,nvidia_drm,drm_kms_helper

dcml@sun:~$ nvidia-smi
Sat Dec  9 12:49:29 2017
+—————————————————————————–+
| NVIDIA-SMI 384.98                 Driver Version: 384.98                    |
|——————————-+———————-+———————-+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 106…  Off  | 00000000:01:00.0  On |                  N/A |
| 35%   30C    P8     6W / 120W |    206MiB /  6069MiB |      2%      Default |
+——————————-+———————-+———————-+

+—————————————————————————–+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1085      G   /usr/lib/xorg/Xorg                           132MiB |
+—————————————————————————–+

apt-get Update – Hash-Mismatch
sudo apt-get clean
sudo apt-get update
sudo sed -i -re ‘s/\w+\.archive\.ubuntu\.com/archive.ubuntu.com/g’ /etc/apt/sources.list

Open SSH
apt-get install openssh-server

Annaconda
https://repo.continuum.io/archive/Anaconda2-5.0.1-Linux-x86_64.sh

Install path – /opt/anaconda2

Anaconda Clean Remove
conda install anaconda-clean
anaconda-clean –yes
rm -rf ~/anaconda2
rm -rf ~/.anaconda_backup

Open CV with CUDA
apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev
apt-get install libgtk2.0-dev
apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
apt-get install libatlas-base-dev gfortran
apt-get install libhdf5-serial-dev
apt-get install python2.7-dev
apt-get install yad

apt-get install build-essential cmake git unzip pkg-config
apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
apt-get install libxvidcore-dev libx264-dev
apt-get install libgtk-3-dev
apt-get install libhdf5-serial-dev graphviz
apt-get install libopenblas-dev libatlas-base-dev gfortran
apt-get install python-tk python3-tk python-imaging-tk

apt-get install python2.7-dev python3-dev
apt-get install linux-image-generic linux-image-extra-virtual
apt-get install linux-source linux-headers-generic

apt-get update
apt-get upgrade

Numpy
apt-get install python-pip
pip install –upgrade pip

pip install numpy scipy
apt-get install python-numpy python-scipy

Opencv
wget -O opencv_3.3.1.zip https://github.com/opencv/opencv/archive/3.3.1.zip
wget -O opencv_contrib_3.3.1.zip https://github.com/Itseez/opencv_contrib/archive/3.1.1.zip

ffmpeg
add-apt-repository ppa:jonathonf/ffmpeg-3
apt-get install ffmpeg
  update && apt upgrade

Atom
wget https://github.com/atom/atom/releases/download/v1.22.1/atom-amd64.deb
dpkg -i atom-amd64.deb

cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=/home/dcml/opencv_build/opencv_cuda/opencv_contrib-3.1.0/modules \
-D BUILD_EXAMPLES=ON \
-D WITH_TBB=ON \
-D WITH_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
..

cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=/home/dcml/opencv_build/opencv_cuda/opencv_contrib-3.1.0/modules \
-D BUILD_EXAMPLES=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
..

make -j 2
sudo make install

PyQT
apt-get install python-qt4 pyqt4-dev-tools qt4-designer
apt-get install qtcreator
apt-get install qt4-designer
apt-get install python-pyqt5
apt-get install python-qt4 qt4-designer

Run – designer-qt4

CUDA
wget http://192.168.1.27:8000/cuda_8.0.61_375.26_linux-run
dcml@sun:~/Downloads$ sudo bash cuda_8.0.61_375.26_linux-run
Logging to /tmp/cuda_install_9246.log
Using more to view the EULA.
End User License Agreement
————————–

Preface
——-

The following contains specific license terms and conditions
for four separate NVIDIA products. By accepting this
agreement, you agree to comply with all the terms and
conditions applicable to the specific product(s) included
herein.

NVIDIA CUDA Toolkit

Description

The NVIDIA CUDA Toolkit provides command-line and graphical
tools for building, debugging and optimizing the performance
of applications accelerated by NVIDIA GPUs, runtime and math
libraries, and documentation including programming guides,
user manuals, and API references. The NVIDIA CUDA Toolkit
License Agreement is available in Chapter 1.

Default Install Location of CUDA Toolkit

Windows platform:

%ProgramFiles%\NVIDIA GPU Computing Toolkit\CUDA\v#.#
Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?
(y)es/(n)o/(q)uit: n

Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
  [ default is /usr/local/cuda-8.0 ]:

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
  [ default is /home/dcml ]:

Installing the CUDA Toolkit in /usr/local/cuda-8.0 …
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/dcml …
Copying samples to /home/dcml/NVIDIA_CUDA-8.0_Samples now…
Finished copying samples.

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-8.0
Samples:  Installed in /home/dcml, but missing recommended libraries

Please make sure that
  –   PATH includes /usr/local/cuda-8.0/bin
  –   LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.

***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
     sudo <CudaInstaller>.run -silent -driver

Logfile is /tmp/cuda_install_9246.log

apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev
apt-get install libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev libglfw3-dev libgles2-mesa-dev

Cleanup
apt autoremove

root@sun:~# cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
root@sun:/usr/local/cuda-8.0/samples/1_Utilities/deviceQuery# make
“/usr/local/cuda-8.0″/bin/nvcc -ccbin g++ -I../../common/inc  -m64    -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_60,code=compute_60 -o deviceQuery.o -c deviceQuery.cpp
nvcc warning : The ‘compute_20’, ‘sm_20’, and ‘sm_21’ architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
“/usr/local/cuda-8.0″/bin/nvcc -ccbin g++   -m64      -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_60,code=compute_60 -o deviceQuery deviceQuery.o
nvcc warning : The ‘compute_20’, ‘sm_20’, and ‘sm_21’ architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
mkdir -p ../../bin/x86_64/linux/release
cp deviceQuery ../../bin/x86_64/linux/release
root@sun:/usr/local/cuda-8.0/samples/1_Utilities/deviceQuery# ./deviceQuery
./deviceQuery Starting…

CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: “Ge GTX 1060 6GB”
   CUDA Driver Version / Runtime Version          9.0 / 8.0
   CUDA Capability Major/Minor version number:    6.1
   Total amount of global memory:                 6070 MBytes (6364463104 bytes)
   (10) Multiprocessors, (128) CUDA Cores/MP:     1280 CUDA Cores
   GPU Max Clock rate:                            1759 MHz (1.76 GHz)
   Memory Clock rate:                             4004 Mhz
   Memory Bus Width:                              192-bit
   L2 Cache Size:                                 1572864 bytes
   Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
   Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
   Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
   Total amount of constant memory:               65536 bytes
   Total amount of shared memory per block:       49152 bytes
   Total number of registers available per block: 65536
   Warp size:                                     32
   Maximum number of threads per multiprocessor:  2048
   Maximum number of threads per block:           1024
   Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
   Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
   Maximum memory pitch:                          2147483647 bytes
   Texture alignment:                             512 bytes
   Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
   Run time limit on kernels:                     Yes
   Integrated GPU sharing Host Memory:            No
   Support host page-locked memory mapping:       Yes
   Alignment requirement for Surfaces:            Yes
   Device has ECC support:                        Disabled
   Device supports Unified Addressing (UVA):      Yes
   Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
   Compute Mode:
      < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 1060 6GB
Result = PASS

export CMAKE_CXX_FLAGS=-std=c++11

apt-get install liblapacke-dev checkinstall
apt-get install libavresample-dev
apt-get install libgphoto2
apt-get install libgphoto2-dev
apt-get install libdc1394-22
apt-get install libdc1394-22-dev
apt-get install liblapacke-dev checkinstall
apt-get install libxine2-dev

cmake -D CMAKE_BUILD_TYPE=RELEASE \
     -D CMAKE_INSTALL_PREFIX=/usr/local \
     -D INSTALL_C_EXAMPLES=ON \
     -D INSTALL_PYTHON_EXAMPLES=ON \
     -D OPENCV_EXTRA_MODULES_PATH=/home/dcml/opencv_build/opencv_contrib-3.3.1/modules \
     -D BUILD_EXAMPLES=ON \
     -D WITH_TBB=ON \
     -D WITH_CUDA=ON \
     -D ENABLE_FAST_MATH=1 \
     -D CUDA_FAST_MATH=1 \
     -D WITH_CUBLAS=1 \
     -D BUILD_NEW_PYTHON_SUPPORT=ON \
     ..

Building and running Python demo of
Simple Vehicle Counting
Vehicle Detection, Tracking and Counting

https://github.com/andrewssobral/simple_vehicle_counting

1. Install Boost library for Python
sudo apt-get install libboost-python-dev

2. Clone the repo
mkdir work
cd work
git clone –recursive https://github.com/andrewssobral/simple_vehicle_counting.git

3. Apply Patch
cd simple_vehicle_counting
patch -p1 <fix.diff
git diff

4. Build
cd build
mkdir python
cp -r ../python/* python
cmake -D BUILD_PYTHON_SUPPORT=ON ..
make

5. Run demo
../run_python_demo.sh

fix.diff
diff –git a/CMakeLists.txt b/CMakeLists.txt
index c205e27..5a5fd9b 100644
— a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,7 +41,7 @@ endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)

IF (UNIX)
      # add some standard warnings
–    ADD_DEFINITIONS(-Wno-variadic-macros -Wno-long-long -Wall -Wextra -Winit-self -Woverloaded-virtual -Wsign-promo -Wno-unused-parameter -pedantic -Woverloaded-virtual -Wno-unknown-pragmas)
+    ADD_DEFINITIONS(-Wno-variadic-macros -Wno-long-long -Wall -Wextra -Winit-self -Woverloaded-virtual -Wsign-promo -Wno-unused-parameter -pedantic -Woverloaded-virtual -Wno-unknown-pragmas -fPIC)

     # -ansi does not compile with sjn module
      #ADD_DEFINITIONS(-ansi)

Install OpenCV-Python with FFMPEG to Anaconda

I have summarized my now fully working solution OpenCV-Python – How to install OpenCV-Python package to Anaconda (Windows). Nevertheless I’ve

To use OpenCV fully with Anaconda (and Spyder IDE), we need to:

  1. Download the OpenCV package from the official OpenCV site
  2. Copy and paste the cv2.pyd to the Anaconda site-packages directory.
  3. Set user environmental variables so that Anaconda knows where to find the FFMPEG utility.
  4. Do some testing to confirm OpenCV and FFMPEG are now working.

Prerequisite

Install Anaconda

Anaconda is essentially a nicely packaged Python IDE that is shipped with tons of useful packages, such as NumPy, Pandas, IPython Notebook, etc. It seems to be recommended everywhere in the scientific community. Check out Anaconda to get it installed.

Install OpenCV-Python to Anaconda

Cautious Note: I originally tried out installing the binstar.org opencv package, as suggested. That method however does not include the FFMPEG codec – i.e. you may be able to use OpenCV but you won’t be able to process videos.

The following instruction works for me is inspired by this OpenCV YouTube video. So far I have got it working on both my Desktop and Laptop. Both 64-bit machines and Windows 8.1.

Download OpenCV Package

Firstly, go to the official OpenCV site to download the complete OpenCV package. Pick a version you like (2.x or 3.x). I am on Python 2.x and OpenCV 3.x – mainly because this is how the OpenCV-Python Tutorials are setup/based on.

In my case, I’ve extracted the package (essentially a folder) straight to my C drive. (C:\opencv).

Copy and Paste the cv2.pyd file

The Anaconda Site-packages directory (e.g. C:\Users\Johnny\Anaconda\Lib\site-packages in my case) contains the Python packages that you may import. Our goal is to copy and paste the cv2.pyd file to this directory (so that we can use the import cv2 in our Python codes.).

To do this, copy the cv2.pyd file…

From this OpenCV directory (the beginning part might be slightly different on your machine):

# Python 2.7 and 32-bit machine: 
C:\opencv\build\python\2.7\x84

# Python 2.7 and 64-bit machine: 
C:\opencv\build\python\2.7\x64

To this Anaconda directory (the beginning part might be slightly different on your machine):

C:\Users\Johnny\Anaconda\Lib\site-packages

After performing this step we shall now be able to use import cv2 in Python code. BUT, we still need to do a little bit more work to get FFMPEG (video codec) to work (to enable us to do things like processing videos.)

Set Enviromental Variables

Right-click on “My Computer” (or “This PC” on Windows 8.1) -> left-click Properties -> left-click “Advanced” tab -> left-click “Environment Variables…” button.

Add a new User Variable to point to the OpenCV (either x86 for 32-bit system or x64 for 64-bit system.) I am currently on a 64-bit machine.

| 32-bit or 64 bit machine? | Variable     | Value                                |
|---------------------------|--------------|--------------------------------------|
| 32-bit                    | `OPENCV_DIR` | `C:\opencv\build\x86\vc12`           |
| 64-bit                    | `OPENCV_DIR` | `C:\opencv\build\x64\vc12`           |

Append %OPENCV_DIR%\bin to the User Variable PATH.

For example, my PATH user variable looks like this…

Before:

C:\Users\Johnny\Anaconda;C:\Users\Johnny\Anaconda\Scripts

After:

C:\Users\Johnny\Anaconda;C:\Users\Johnny\Anaconda\Scripts;%OPENCV_DIR%\bin

This is it we are done! FFMPEG is ready to be used!

Test to confirm

We need to test whether we can now do these in Anaconda (via Spyder IDE):

  • Import OpenCV package
  • Use the FFMPEG utility (to read/write/process videos)
Test 1: Can we import OpenCV?

To confrim that Anaconda is now able to import the OpenCV-Python package (namely, cv2), issue these in the IPython Console:

import cv2
print cv2.__version__

If the package cv2 is imported ok with no errors, and the cv2 version is printed out, then we are all good! Here is a snapshot:

import-cv2-ok-in-anaconda-python-2.png http://mathalope.co.uk/wp-content/uploads/2015/07/import-cv2-ok-in-anaconda-python-2.png

Test 2: Can we Use the FFMPEG codec?

Place a sample input_video.mp4 video file in a directory. We want to test whether we can:

  • read this .mp4 video file, and
  • write out a new video file (can be .avi or .mp4 etc.)

To do this we need to have a test python code, call it test.py. Place it in the same directory as the sample input_video.mp4 file.

This is what test.py may look like (I’ve listed out both newer and older version codes here – do let us know which one works / not work for you!):

(Newer verison…)

import cv2
cap = cv2.VideoCapture("input_video.mp4")
print cap.isOpened()   # True = read video successfully. False - fail to read video.

fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter("output_video.avi", fourcc, 20.0, (640, 360))
print out.isOpened()  # True = write out video successfully. False - fail to write out video.

cap.release()
out.release()

(or the older version…)

import cv2
cv2.VideoCapture("input_video.mp4")
print cv2.isOpened()   # True = read video successfully. False - fail to read video.

fourcc = cv2.cv.CV_FOURCC(*'XVID')
out = cv2.VideoWriter("output_video.avi",fourcc, 20.0, (640,360))
print out.isOpened()  # True = write out video successfully. False - fail to write out video.

cap.release()
out.release()

This test is VERY IMPORTANT. If you’d like to process video files, you’d need to ensure that Anaconda / Spyder IDE can use the FFMPEG (video codec). It took me days to have got it working. But I hope it would take you much less time! 🙂

Note: one more very important tip when using the Anaconda Spyder IDE. Make sure you check the Current Working Directory (CWD)!!!

Conclusion

To use OpenCV fully with Anaconda (and Spyder IDE), we need to:

  1. Download the OpenCV package from the official OpenCV site
  2. Copy and paste the cv2.pyd to the Anaconda site-packages directory.
  3. Set user environmental variables so that Anaconda knows where to find the FFMPEG utility.
  4. Do some testing to confirm OpenCV and FFMPEG are now working.

Good luck!

NASA’s 10 rules for developing safety-critical code

1: Restrict all code to very simple control flow constructs. Do not use GOTO statements, setjmp or longjmp constructs, or direct or indirect recursion.

2: All loops must have a fixed upper bound. It must be trivially possible for a checking tool to statically prove that a preset upper bound on the number of iterations of a loop cannot be exceeded. If the loop-bound cannot be proven statically, the rule is considered violated.

3: Do not use dynamic memory allocation after initialization.

4: No function should be longer than what can be printed on a single sheet of paper (in a standard reference format with one line per statement and one line per declaration.) Typically, this means no more than about 60 lines of code per function.

5: The assertion density of the code should average a minimum of two assertions per function. Assertions must always be side effect-free and should be defined as Boolean tests.

6: Data objects must be declared at the smallest possible level of scope.

7: Each calling function must check non-void function return values, and the validity of parameters must be checked inside each function.

8: Preprocessor use must be limited to the inclusion of header files and simple macro definitions. Token pasting, variable argument lists (ellipses), and recursive macro calls are not allowed.

9: The use of pointers should be restricted. Specifically, no more than one level of dereferencing is allowed. Pointer dereference operations may not be hidden in macro definitions or inside typedef declarations. Function pointers are not permitted.

10: All code must be compiled, from the first day of development, with all compiler warnings enabled at the compiler’s most pedantic setting. All code must compile with these setting without any warnings. All code must be checked daily with at least one—but preferably more than one—state-of-the-art static source code analyzer, and should pass the analyses with zero warnings.

What’s the value of life?

A little boy went to his old grandpa and asked, “What’s the value of life?”

The grandpa gave him one stone and said, “Find out the value of this stone, but don’t sell it.”

The boy took the stone to an Orange Seller and asked him what its cost would be.

The Orange Seller saw the shiny stone and said, “You can take 12 oranges and give me the stone.”

The boy apologized and said that the grandpa has asked him not to sell it.

He went ahead and found a vegetable seller.

“What could be the value of this stone?” he asked the vegetable seller.

The seller saw the shiny stone and said, “Take one sack of potatoes and give me the stone.”

The boy again apologized and said he can’t sell it.

Further ahead, he went into a jewellery shop and asked the value of the stone.

The jeweler saw the stone under a lens and said, “I’ll give you 1 million for this stone.”

When the boy shook his head, the jeweler said, “Alright, alright, take 2 24karat gold necklaces, but give me the stone.”

The boy explained that he can’t sell the stone.

Further ahead, the boy saw a precious stone’s shop and asked the seller the value of this stone.

When the precious stone’s seller saw the big ruby, he lay down a red cloth and put the ruby on it.

Then he walked in circles around the ruby and bent down and touched his head in front of the ruby. “From where did you bring this priceless ruby from?” he asked.

“Even if I sell the whole world, and my life, I won’t
be able to purchase this priceless stone.”

Stunned and confused, the boy returned to the grandpa and told him what had happened.

“Now tell me what is the value of life, grandpa?”

Grandpa said,

“The answers you got from the Orange Seller, the Vegetable Seller, the Jeweler & the Precious Stone’s Seller explain the value of our life…

You may be a precious stone, even priceless, but, people will value you based on their intellectual status, their level of information, their belief in you, their motive behind entertaining you, their ambition, their risk taking ability & ultimately their calibre.

So don’t fear, you will surely find someone who will discern your true value.”

Respect yourself.

Don’t sell yourself cheap.

You are rare, Unique, Original and the only one of ur kind.

Your are a masterpiece because u r  the MASTER’S PIECE.

No one can Replace you.

Have a Great Life