Skip to content

Instantly share code, notes, and snippets.

View StevenPuttemans's full-sized avatar

Steven Puttemans StevenPuttemans

View GitHub Profile
@StevenPuttemans
StevenPuttemans / warp_rectangles.cpp
Created March 24, 2017 14:09
[OPENCV3.2] Warping rotated rects back to a horizontal position
/// Considering you have a contour available after segmentation
/// Considering you have an image where the contour is found
vector<Point> contour;
Mat image;
/// Get the RotatedRect associated with the contour
RotatedRect rect = minAreaRect(contour);
/// Also select the corner points for rotating back
Point2f pts[4]; rect.points(pts);
/// Define the angle of rotation and rotate the selection to an upright position
/// This will work for slight rotations, once going over 45 degrees this might result in wrong transformations
@StevenPuttemans
StevenPuttemans / merge_channels.cpp
Last active March 24, 2017 14:11
[OPENCV3.2] Efficiently merge single channels into multi channel matrix
// Approach 1
Mat result_channel(rows, cols, CV_8UC3);
Mat in[] = { blue_channel, green_channel, red_channel };
int from_to[] = { 0,0, 1,1, 2,2 };
mixChannels( in, 3, &result_channel, 1, from_to, 3 );
// Approach 2
blue_channel.copyTo( result_channel( Rect(0, 0, cols, rows) ) );
green_channel.copyTo( result_channel( Rect(cols, 0, cols, rows) ) );
red_channel.copyTo( result_channel( Rect(cols*2, 0, cols, rows) ) );
@StevenPuttemans
StevenPuttemans / OpenCV_with_SFM_support.md
Created April 13, 2017 09:47
Enabling SFM support with Ceres in OpenCV3.2

If your Ceres installation is built with C++11 instructions enabled, then make sure you tell OpenCV to build its modules with c++11 support. This can be done by adding the following entry inside your cmake gui

  • Make an new entry with CMAKE_CXX_STANDARD = 11
  • Or simply add -DCMAKE_CXX_STANDARD=11
/// Initialize the tracking interface
cv::MultiTracker faceTrackers("KCF");
vector< cv::Rect > objectsToTrack;
while(true){
capture >> frame;
std::vector< cv::Rect > dets_OpenCV;
model.detectMultiScale(frame, dets_OpenCV, 1.2, 3);
@StevenPuttemans
StevenPuttemans / config.md
Last active May 2, 2017 11:51
Make CAFFE and dependant frameworks find HDF5

Make your installation aware of the HDF5 libs, that have changing names:

spu@dellSPU:/usr/lib/x86_64-linux-gnu$ sudo ln -s libhdf5_serial.so libhdf5.so
spu@dellSPU:/usr/lib/x86_64-linux-gnu$ sudo ln -s libhdf5_serial_hl.so libhdf5_hl.so
watch -n 0.1 nvidia-smi
@StevenPuttemans
StevenPuttemans / config.md
Created May 3, 2017 12:41
Control fans desktop

Settings selected: sudo pwmconfig

Settings for hwmon0/device/pwm2:  
Depends on hwmon0/device/temp2_input  
Controls hwmon0/device/fan2_input  
MINTEMP=40  
MAXTEMP=60  
MINSTART=150  
MINSTOP=0 
@StevenPuttemans
StevenPuttemans / command.md
Created May 19, 2017 08:29
Remove all trailing whitespaces, from a set of given text files

Command to use: find . -type f -name '*.txt' -exec sed --in-place 's/[[:space:]]\+$//' {} \+

@StevenPuttemans
StevenPuttemans / convert.sh
Created May 24, 2017 10:44
Batch convert png files to jpg files
ls -1 *.png | xargs -n 1 bash -c 'convert "$0" "${0%.png}.jpg"'
@StevenPuttemans
StevenPuttemans / command.md
Created June 12, 2017 11:29
Merge darknet upstream changes into a single commit

This can be done with the following commands

git pull --squash origin_PJREDDIE master
git add --all
git commit -m "Merge upstream PJReddie fixes"
git push -f https://gitlab.com/EAVISE/darknet.git master

Of course, if during the pull merge conflicts appear, you need to solve those first.