Skip to content

Instantly share code, notes, and snippets.

View qingswu's full-sized avatar

qingswu

  • Canada
View GitHub Profile
@qingswu
qingswu / tf_data_augmentation_on_gpu.py
Created September 17, 2020 13:44 — forked from vertix/tf_data_augmentation_on_gpu.py
TF data augmentation on GPU
def augment(images, labels,
resize=None, # (width, height) tuple or None
horizontal_flip=False,
vertical_flip=False,
rotate=0, # Maximum rotation angle in degrees
crop_probability=0, # How often we do crops
crop_min_percent=0.6, # Minimum linear dimension of a crop
crop_max_percent=1., # Maximum linear dimension of a crop
mixup=0): # Mixup coeffecient, see https://arxiv.org/abs/1710.09412.pdf
if resize is not None:
def get_versions():
versions = []
import sys
versions.append('Python verison: {}.{}.{}'.format(sys.version_info.major, sys.version_info.minor, sys.version_info.micro))
import cv2
versions.append('OpenCV: {}'.format(cv2.__version__))
import numpy as np
@qingswu
qingswu / vidoe_cap_proc.cpp
Created May 9, 2019 04:12
Basic video capture template
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>
int main(int argc, char** argv) {
cv::VideoCapture cap(0);
// cap.set(cv::CAP_PROP_FRAME_WIDTH, 1280);
// cap.set(cv::CAP_PROP_FRAME_HEIGHT, 720);
cv::Mat im;
@qingswu
qingswu / client.cpp
Created November 21, 2017 04:57 — forked from SteveRuben/client.cpp
Multiple streaming in c++ using opencv; OpenCV video streaming over TCP/IP
/**
* OpenCV video streaming over TCP/IP
* Client: Receives video from server and display it
* by Steve Tuenkam
*/
#include "opencv2/opencv.hpp"
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
@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 <[email protected]>
* @copyright computer-vision-talks.com/articles/how-to-detect-circles-in-noisy-image/
*/
#include <opencv2/opencv.hpp>
# 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 / 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 ..
@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 / 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 / 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__)