This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create random Mat | |
int rows = 10, cols = 10; | |
cv::Mat m = cv::Mat::zeros(rows, cols, CV_32F); | |
cv::RNG(cv::getTickCount().fill(m, cv::RNG::UNIFORM, cv::Scalar(0), cv::Scalar(1)); | |
// or you can use randu and randn. I prefer RNG, because I can set the seed. | |
randu(m, cv::Scalar(0), cv::Scalr(1)); | |
// change one line | |
cv::mat row = m.row(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import os, shutil | |
def remove_files_dirs(dir = '.'): | |
''' remove all files and dirs in cwd ''' | |
print "Current work dir: " + os.getcwd() | |
judge = raw_input("remove all?[Y/n]") | |
if judge == 'n': | |
exit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import qualified Random | |
main :: IO () | |
main = do | |
a <- randInt 0 100 | |
putStrLn $ show a | |
-- generate random number between [lo, hi] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding = utf-8 -*- | |
import urllib, urllib2, sys | |
from BeautifulSoup import BeautifulSoup # for html | |
def fetch_url(link): | |
''' ''' | |
f = urllib.urlopen(link) | |
contents = f.read() | |
f.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Control.Monad.State | |
type IntState = State Int | |
inc :: IntState () | |
-- inc = get >>= put . (+1) | |
inc = do | |
v <- get |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- from Real World Haskell, Chapter 9 | |
module RecursiveContents (getRecursiveContents) where | |
import Control.Monad (forM) | |
import System.Directory (doesDirectoryExist, getDirectoryContents, getCurrentDirectory) | |
import System.FilePath ((</>)) | |
getRecursiveContents :: FilePath -> IO [FilePath] | |
getRecursiveContents topdir = do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "open-uri" | |
require "net/http" | |
Net::HTTP.version_1_2 | |
uri = URI.parse("http://192.168.1.1") | |
http = Net::HTTP.new(uri.host, uri.port) | |
while true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import cv2 | |
if __name__ == "__main__": | |
''' ''' | |
camera = cv2.VideoCapture(0) | |
while True: | |
# cv2.VideoCapture return a tuple, (Bool, Numpy.ndarray) | |
_, im = camera.read() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from distutils.core import setup | |
import py2exe | |
setup( | |
options = {"py2exe": {"bundle_files": 1, "includes": "numpy"}}, | |
console=["readCamera.py"], | |
zipfile = None, | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compile by: g++ hello.cxx -shared -fPIC -o hello.so -I/usr/include/python2.7 -lboost_python | |
#include <string> | |
#include <boost/python.hpp> | |
using std::string; | |
using namespace boost::python; | |
string hello() { return "Hello, world!"; } | |
// add a argument |
OlderNewer