Skip to content

Instantly share code, notes, and snippets.

$ sudo gem install cocoapods
newImage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
_ , contours, _ = cv2.findContours(res, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(newImage, contours, -1, (255, 255, 0), 1)
for cnt in contours:
M = cv2.moments(cnt)
(x,y),radius = cv2.minEnclosingCircle(cnt)
if(radius > 10):
center = (int(x),int(y))
radius = int(radius)
cv2.circle(newImage,center,radius,(0,255,0),2)
mask = cv2.GaussianBlur(hsv, (11, 11), 0)
mask = cv2.inRange(mask, lower_range, upper_range)
res = cv2.bitwise_and(hsv, hsv, mask=mask)
res = cv2.cvtColor(cv2.cvtColor(res, cv2.COLOR_HSV2BGR), cv2.COLOR_BGR2GRAY)
res = cv2.erode(res, None, iterations=3)
res = cv2.dilate(res, None, iterations=4)
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
_, img = cap.read()
#Convert BGR colour space that the camera picks up to HSV
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
import numpy as np
import cv2
import os
import sys
import time
import picamera
import picamera.array
import argparse
def objectFound():
$ sudo raspi-config
//Then Select Interfacing Options
//Then Select camera and activate
//It will ask you to reboot and select Yes
$ rm -rf opencv-3.1.0 opencv_contrib-3.1.0
$ source ~/.profile
$ workon cv
$ python
>>> import cv2
>>> cv2.__version__
'3.1.0'
>>>
//Python 2
$ ls -l /usr/local/lib/python2.*/site-packages/
total 1852
-rw-r--r-- 1 root staff 1895772 Mar 20 20:00 cv2.so
//Get file path and move to global packages
$ cd ~/.virtualenvs/cv/lib/python2.7/site-packages/
$ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so