Python machine vision

Python machine vision LCD OCR WTF

I just finished getting a camera through a usb adapter visible in python, and now I’m getting the machine vision set up. I found someone who already did all the hard stuff. I used this LCD numbers image since it had the same font as the display on the Dylos air quality monitor. I had to adjust the perspective to make it flat for the machine vision training though, so I used gimp to do that. Then I realized there was a 0 with a line under it, so I replaced that with another 0 from lines below. After that, I started training the program, but it was seeing 4s and 1s. I had to change the threshhold for detection from

thresh = cv2.adaptiveThreshold(blur,255,1,1,11,2)

to this

thresh = cv2.adaptiveThreshold(blur,255,0,1,25,-2)

The docs describe this function a bit, although I can’t get the cv2.CV_ADAPTIVE_THRESH_MEAN_C to print, so I’m not entirely sure which adaptive_method I’m using (I think I changed it from gaussian, 1, to linear, 0). I empirically found the higher block size and lower constant seem to work best for this image. After that, it works well.

Read more

Camera and easyCAP usb

Camera troubles

I’m setting up a calibration platform for particle sensors, and I need a camera to capture the data from the Dylos sensor, because it only outputs data over serial once per minute, and I need once per second. So I need to capture an image of the number output on the display, process it and extract the data. Unfortunately, I don’t have any webcams lying around the house, and I’m not about to go spend $20 for one when I have another camera here. It’s a small camera, probably the same as in your laptop and webcams. (I was going to use it as a remote security webcam, but then I found out it’s much harder to interface a camera with a microcontroller than I thought.) So I hooked it up to an easyCAP I have with a patch cable, and tried to interface it with Python on a Windows laptop, which became very difficult. Eventually, I was able to get it working with this tip. The steps I had to take to get it working were:

The cd that came with easyCAP is here if anyone needs it.

With linux, this is easier because you can call mplayer with subprocess.

Read more

Air quality and your health


The quality of the air we breathe is not something we often think about, because most of the air we breathe is clear (over short distances), so we don’t notice the pollution. However, modern-day technologies like cars, trucks, power plants, and factories, are polluting our air. It’s only going to get worse with increasing populations and consumption of energy, while we’re still using the same technologies. To protect and optimize your health, it’s best to monitor your air quality and purify it when necessary.

Do you clear your throat a lot? Cough often? Have congested nasal passages and sinuses, manifesting headaches and pain? Chest pain, feeling tired a lot, dry/sore throat all the time, get sick a lot? If you don’t, surely you know someone who does, unless you’re lucky enough to live in a clean-air area, which is probably not near a densely-populated area. Many health problems can arise from poor air quality:

  • chest pain, headaches, nausea, allergies, eye irritation
  • weakened athletic performance, increased fatigue, reduced resistance to infection
  • respiratory problems: coughing, sore and/or dry throat, shortness of breath, emphysema, bronchitis, asthma
  • mucus and sinus problems: post-nasal drip, sinus headaches and congestion,
  • death: heart attacks and arrythmia, cancer, strokes

It usually sneaks up on people (like slowly heating up the water to boil a frog), but in cases with spikes of high amounts of particles, can cause death within days to weeks. Air pollution is getting more and more attention; the World Health Organization recently declared that 1 in 8 deaths is linked to air pollution, and “that air pollution is now the world’s largest single environmental health risk.” Chronic exposure will give you cancer (the small particles have lots of surface area and free radicals that damage your body), and take off 1-3 years of your life. Other impacts range from premature births to serious respiratory disorders, even when the particle levels are very low.

Read more

Air quality measurement devices


After developing chronic sinusitis, which was giving me nasty headaches and mucus problems, I decided to start measuring my air quality in order to remedy my situation. What I found was an unpalatable surprise–pretty much anywhere with decent concentration of cars and trucks has bad air quality. Since I didn’t want to spend $200 on an air quality monitor, I started building my own from electronic components.

Options for sensors

There is essentially one company that makes inexpensive air quality sensors–Shinyei, a Japanese company. Their cheapest model is the PPD42NJ, which a Korean company–Samyoung copied (called the DSM501). The Samyoung model can be purchased for a few dollars on aliexpress, the Shinyei model is about 2x the cost, but seems more accurate. Shinyei also makes much more expensive sensors, with better sensitivity (the PPD60V).

First prototype

Sometime in the Fall, while searching on the internet for reasons for congested sinuses and mucus buildup, I came across air quality measurements and their effect on health, and purchased one of the Shinyei PPD42 sensors. I hooked it up to an Arduino, and started logging data on my local machine (Github here), using the code from Chris Nafis. I then started noticing trends, like air quality getting worse as people cooked and rush hour ensued, and noticed I could bring my air quality into a healthy range with an inexpensive DIY air purifier.

I built a prototype, using an Arduino, LCD screen, and the Shinyei dust sensor (instructions here). The accuracy seemed on par with the $200+ Dylos counter:


Read more

Measuring progress

If you can measure it, you can manage it.

That was something I heard a former Wal-Mart CEO, Mike Duke, say at the WSJ ECO:nomics 2014 conference; “If you can measure it, you can manage it.” I think it’s best to measure everything we can, and ideally our progress in different aspects of our life.

So how do you measure progress?

Read more