Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ pandoc: false
matrix:
include:
- dist: xenial # up-to-date 3.4 branch
addons:
apt:
update: true
sources:
- sourceline: 'ppa:cran/opencv'
packages:
- libopencv-dev
- opencv-data
- dist: xenial # 3.2 branch (Bionic / Buster)
addons:
apt:
Expand All @@ -20,18 +28,12 @@ matrix:
- os: osx
brew_packages: opencv@3
env: PKG_CONFIG_PATH="/usr/local/opt/opencv@3/lib/pkgconfig"
- os: osx
brew_packages: opencv@2
env: PKG_CONFIG_PATH="/usr/local/opt/opencv@2/lib/pkgconfig"
- os: osx
brew_packages: opencv
- os: osx
osx_image: xcode7.3
disable_homebrew: true
before_install: sed -i.bak 's/-isysroot /-I/g' $(R RHOME)/etc/Makeconf

addons:
apt:
update: true
sources:
- sourceline: 'ppa:cran/opencv'
packages:
- libopencv-dev
- opencv-data
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Description: Experimenting with computer vision and machine learning in R. This
such as edge, body or face detection. These can either be applied to analyze
static images, or to filter live video footage from a camera device.
License: MIT + file LICENSE
SystemRequirements: OpenCV: libopencv-dev (Debian, Ubuntu) or opencv-devel (Fedora)
SystemRequirements: OpenCV 3 or newer: libopencv-dev (Debian, Ubuntu) or opencv-devel (Fedora)
URL: https://docs.ropensci.org/opencv, https://opencv.org (upstream) https://github.com/ropensci/opencv (devel)
BugReports: https://github.com/ropensci/opencv/issues
LinkingTo: Rcpp
Expand Down
2 changes: 1 addition & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ is_check <- function(){
}

is_mojave <- function(){
ver <- utils::tail(strsplit(sessionInfo()$running, ' ')[[1]], 1)
ver <- utils::tail(strsplit(utils::sessionInfo()$running, ' ')[[1]], 1)
as.numeric_version(ver) >= "10.14"
}

Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PKG_CONFIG_NAME="opencv4"
PKG_CONFIG_NAME_ALT="opencv"
PKG_DEB_NAME="libopencv-dev"
PKG_RPM_NAME="opencv-devel"
PKG_BREW_NAME="opencv"
PKG_BREW_NAME="opencv@2"
PKG_TEST_HEADER="<opencv2/opencv.hpp>"
PKG_LIBS="-lopencv_{stitching,superres,videostab,aruco,bgsegm,bioinspired,ccalib,dnn_objdetect,\
dpm,face,photo,fuzzy,hfs,img_hash,line_descriptor,optflow,reg,rgbd,saliency,stereo,structured_light,\
Expand Down
8 changes: 8 additions & 0 deletions src/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ XPtrMat cvmat_blur(XPtrMat ptr, size_t ksize){
XPtrMat cvmat_sketch(XPtrMat ptr, bool color){
Mat out1;
Mat out2;
#if CV_VERSION_EPOCH < 3
throw std::runtime_error("pencilSketch requires OpenCV 3 or newer");
#else
pencilSketch(get_mat(ptr),out1, out2, 10 , 0.1f, 0.03f);
#endif
return cvmat_xptr(color ? out2 : out1);
}

// [[Rcpp::export]]
XPtrMat cvmat_stylize(XPtrMat ptr){
Mat out;
#if CV_VERSION_EPOCH < 3
throw std::runtime_error("stylization requires OpenCV 3 or newer");
#else
stylization(get_mat(ptr), out);
#endif
return cvmat_xptr(out);
}
8 changes: 8 additions & 0 deletions src/face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,30 @@ XPtrMat cvmat_facemask(XPtrMat ptr, const char * facedata){

// [[Rcpp::export]]
XPtrMat cvmat_mog2(XPtrMat ptr) {
#if CV_VERSION_EPOCH < 3
throw std::runtime_error("createBackgroundSubtractorMOG2 requires OpenCV 3 or newer");
#else
static Ptr<BackgroundSubtractorMOG2> model = createBackgroundSubtractorMOG2();
model->setVarThreshold(10);
cv::Mat frame = get_mat(ptr);
cv::Mat mask, out_frame;
model->apply(frame, mask);
//refineSegments(frame, mask, out_frame);
return cvmat_xptr(mask);
#endif
}

// [[Rcpp::export]]
XPtrMat cvmat_knn(XPtrMat ptr) {
#if CV_VERSION_EPOCH < 3
throw std::runtime_error("createBackgroundSubtractorKNN requires OpenCV 3 or newer");
#else
static Ptr<BackgroundSubtractorKNN> model = createBackgroundSubtractorKNN();
cv::Mat frame = get_mat(ptr);
cv::Mat mask, out_frame;
model->apply(frame, mask);
return cvmat_xptr(mask);
#endif
}

// [[Rcpp::export]]
Expand Down
3 changes: 2 additions & 1 deletion src/hog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ XPtrMat cvmat_hog(XPtrMat ptr){
r.width = cvRound(r.width*0.8);
r.y += cvRound(r.height*0.07);
r.height = cvRound(r.height*0.8);
rectangle(get_mat(ptr), r.tl(), r.br(), cv::Scalar(0,255,0), 3);
Mat img = get_mat(ptr);
rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 3);
}
return ptr;
}
31 changes: 0 additions & 31 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,3 @@ void detectAndDraw( Mat img, CascadeClassifier& cascade,
}
//imshow( "result", img );
}

void refineSegments(const Mat& img, Mat& mask, Mat& dst)
{
int niters = 3;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
Mat temp;
dilate(mask, temp, Mat(), Point(-1,-1), niters);
erode(temp, temp, Mat(), Point(-1,-1), niters*2);
dilate(temp, temp, Mat(), Point(-1,-1), niters);
findContours( temp, contours, hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE );
dst = Mat::zeros(img.size(), CV_8UC3);
if( contours.size() == 0 )
return;
// iterate through all the top-level contours,
// draw each connected component with its own random color
int idx = 0, largestComp = 0;
double maxArea = 0;
for( ; idx >= 0; idx = hierarchy[idx][0] )
{
const vector<Point>& c = contours[idx];
double area = fabs(contourArea(Mat(c)));
if( area > maxArea )
{
maxArea = area;
largestComp = idx;
}
}
Scalar color( 0, 0, 255 );
drawContours( dst, contours, largestComp, color, FILLED, LINE_8, hierarchy );
}
1 change: 0 additions & 1 deletion src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
void detectAndDraw( cv::Mat img, cv::CascadeClassifier& cascade,
cv::CascadeClassifier& nestedCascade,
double scale, bool tryflip );
void refineSegments(const cv::Mat& img, cv::Mat& mask, cv::Mat& dst);
cv::Mat get_mat(XPtrMat image);
XPtrMat cvmat_xptr(cv::Mat *frame);
XPtrMat cvmat_xptr(cv::Mat orig);