Skip to content

Instantly share code, notes, and snippets.

View qingswu's full-sized avatar

qingswu

  • Canada
View GitHub Profile
@qingswu
qingswu / allocator.hpp
Created March 6, 2016 15:03 — forked from kazuki-ma/allocator.hpp
OpenCV Custom Allocator for OpenGL, DirectX, QImage
// Custom Allocator for OpenCV's cv::Mat
// this code samples writen by facebook.com/matsuda.kazuki and published under public domain.
// You can copy and use this code in any situation under any license.
#ifndef __CVUT_ALLOCATOR__
#define __CVUT_ALLOCATOR__ 1
#include <opencv2/core/core.hpp>
/**
* Fast non-maximum suppression in C, port from
* http://quantombone.blogspot.com/2011/08/blazing-fast-nmsm-from-exemplar-svm.html
*
* @blackball (bugway@gmail.com)
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
@qingswu
qingswu / arma2opencv.hpp
Created March 9, 2016 17:00 — forked from psycharo-zz/arma2opencv.hpp
convertions between armadillo and opencv
// convert an OpenCV multi-channel matrix to Armadillo cube. A copy is made
template <typename T, int NC>
Cube<T> to_arma(const cv::Mat_<cv::Vec<T, NC>> &src)
{
vector<cv::Mat_<T>> channels;
Cube<T> dst(src.cols, src.rows, NC);
for (int c = 0; c < NC; ++c)
channels.push_back({src.rows, src.cols, dst.slice(c).memptr()});
cv::split(src, channels);
return dst;
@qingswu
qingswu / preprocessor_fun.h
Created May 18, 2016 11:17 — forked from aras-p/preprocessor_fun.h
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@qingswu
qingswu / for_each_macro
Created May 19, 2016 14:13 — forked from dhh1128/for_each_macro
"for each"-style macro
// Accept any number of args >= N, but expand to just the Nth one.
// Here, N == 6.
#define _GET_NTH_ARG(_1, _2, _3, _4, _5, N, ...) N
// Define some macros to help us create overrides based on the
// arity of a for-each-style macro.
#define _fe_0(_call, ...)
#define _fe_1(_call, x) _call(x)
#define _fe_2(_call, x, ...) _call(x) _fe_1(_call, __VA_ARGS__)
#define _fe_3(_call, x, ...) _call(x) _fe_2(_call, __VA_ARGS__)
@qingswu
qingswu / png2jpg.py
Last active October 26, 2022 14:05
Convert all png images in current folder to jpg using OpenCV cv2
#!/usr/bin/env python
from glob import glob
import cv2
pngs = glob('./*.png')
for j in pngs:
img = cv2.imread(j)
cv2.imwrite(j[:-3] + 'jpg', img)
@qingswu
qingswu / minmax_rc.py
Last active July 8, 2016 09:12
Get the minimum/maximum width/height of all the jpg images in current folder.
#!/usr/bin/env python
from glob import glob
import cv2
jpgs = glob('./*.jpg')
shapes = [cv2.imread(f).shape for f in jpgs]
a = [list(i) for i in shapes]
width = [row[1] for row in a]
height = [row[0] for row in a]
print 'width min:', min(width), ', max:', max(width), '; height min:', min(height), ', max:', max(height)
@qingswu
qingswu / gist:1c688af97953c2833c96c43092e94c72
Created July 8, 2016 09:15
OpenCV compile with CUDA and python2 in OS X
cmake -DWITH_CUDA=ON -DWITH_CUFFT=ON -DWITH_CUBLAS=ON -DCMAKE_BUILD_TYPE=Release -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -DBUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_DOCS=OFF -DCUDA_ARCH_BIN=3.0 -DCUDA_ARCH_PTX=3.0 -DPYTHON2_LIBRARY=$(python-config --prefix)/lib/libpython2.7.dylib -DPYTHON2_INCLUDE_DIR=$(python-config --prefix)/include/python2.7 ..
# create new build dir
rm -rf build
cd build
cmake .. # some options
cmake --build . --config release --target install # build install
cmake --build . --config releasee --target clean # cleanup
@qingswu
qingswu / eggs_detector.cpp
Created May 18, 2017 02:11 — forked from BloodAxe/eggs_detector.cpp
Image enchancement and Hough transform example
/**
* @brief Image enchancement and Hough transform example
* @author Eugene Khvedchenya <ekhvedchenya@gmail.com>
* @copyright computer-vision-talks.com/articles/how-to-detect-circles-in-noisy-image/
*/
#include <opencv2/opencv.hpp>