Skip to content

Commit

Permalink
Upgrade to visual studio 19 and latest OpenFrameworks
Browse files Browse the repository at this point in the history
Former-commit-id: b08fc7ad2fa0ccc69192372027370a9ae1bfa51f
  • Loading branch information
Marcin Klimek committed Apr 15, 2020
1 parent 15781b5 commit fb8c23d
Show file tree
Hide file tree
Showing 371 changed files with 52,893 additions and 155,382 deletions.
2 changes: 1 addition & 1 deletion addons/ofxCv/example-contours-following/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Glow : public ofxCv::RectFollower {
protected:
ofColor color;
ofVec2f cur, smooth;
ofVec3f cur, smooth;
float startedDying;
ofPolyline all;
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MotionAmplifier {
ySteps = 1+((rescale * h) / stepSize);
for(int y = 0; y < ySteps; y++) {
for(int x = 0; x < xSteps; x++) {
mesh.addVertex(ofVec2f(x, y) * stepSize / rescale);
mesh.addVertex(ofVec3f(ofVec2f(x, y) * stepSize / rescale));
}
}
for(int y = 0; y + 1 < ySteps; y++) {
Expand Down Expand Up @@ -125,4 +125,4 @@ class MotionAmplifier {
void setWindowSize(int windowSize) {
flow.setWindowSize(windowSize);
}
};
};
4 changes: 2 additions & 2 deletions addons/ofxCv/libs/ofxCv/include/ofxCv/Calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ namespace ofxCv {
void undistort(cv::Mat img, int interpolationMode = cv::INTER_LINEAR);
void undistort(cv::Mat src, cv::Mat dst, int interpolationMode = cv::INTER_LINEAR);

ofVec2f undistort(ofVec2f& src) const;
void undistort(std::vector<ofVec2f>& src, std::vector<ofVec2f>& dst) const;
glm::vec2 undistort(glm::vec2& src) const;
void undistort(std::vector<glm::vec2>& src, std::vector<glm::vec2>& dst) const;

bool getTransformation(Calibration& dst, cv::Mat& rotation, cv::Mat& translation);

Expand Down
14 changes: 9 additions & 5 deletions addons/ofxCv/libs/ofxCv/include/ofxCv/ContourFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
// to implement in ContourFinder:
// holes/no holes
// CV_THRESH_OTSU?
// cv::pointPolygonTest - inside, edge, outside
// cv::matchShapes - similarity between two contours
// cv::estimateRigidTransform? subdivision-based estimation for outline-flow?

Expand Down Expand Up @@ -53,10 +52,10 @@ namespace ofxCv {
ofPolyline& getPolyline(unsigned int i);

cv::Rect getBoundingRect(unsigned int i) const;
cv::Point2f getCenter(unsigned int i) const; // center of bounding box (most stable)
cv::Point2f getCentroid(unsigned int i) const; // center of mass (less stable)
cv::Point2f getAverage(unsigned int i) const; // average of contour vertices (least stable)
cv::Vec2f getBalance(unsigned int i) const; // difference between centroid and center
cv::Point2f getCenter(unsigned int i) const; // center of bounding box (most stable)
cv::Point2f getCentroid(unsigned int i) const; // center of mass (less stable)
cv::Point2f getAverage(unsigned int i) const; // average of contour vertices (least stable)
cv::Vec2f getBalance(unsigned int i) const; // difference between centroid and center
double getContourArea(unsigned int i) const;
double getArcLength(unsigned int i) const;
std::vector<cv::Point> getConvexHull(unsigned int i) const;
Expand All @@ -70,6 +69,11 @@ namespace ofxCv {

RectTracker& getTracker();
unsigned int getLabel(unsigned int i) const;

// Performs a point-in-contour test.
// The function determines whether the point is inside a contour, outside, or lies on an edge (or coincides with a vertex)
// The return value is the signed distance (positive stands for inside).
double pointPolygonTest(unsigned int i, cv::Point2f point);

void setThreshold(float thresholdValue);
void setAutoThreshold(bool autoThreshold);
Expand Down
20 changes: 10 additions & 10 deletions addons/ofxCv/libs/ofxCv/include/ofxCv/Flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ namespace ofxCv {
void setPyramidLevels(int levels);

//returns tracking features for this image
std::vector<ofVec3f> getFeatures();
std::vector<ofVec2f> getCurrent();
std::vector<ofVec2f> getMotion();
std::vector<glm::vec3> getFeatures();
std::vector<glm::vec2> getCurrent();
std::vector<glm::vec2> getMotion();

// recalculates features to track
void resetFeaturesToTrack();
void setFeaturesToTrack(const std::vector<ofVec2f> & features);
void setFeaturesToTrack(const std::vector<glm::vec2> & features);
void setFeaturesToTrack(const std::vector<cv::Point2f> & features);
void resetFlow();
protected:
Expand Down Expand Up @@ -129,12 +129,12 @@ namespace ofxCv {
void setUseGaussian(bool gaussian);

cv::Mat& getFlow();
ofVec2f getTotalFlow();
ofVec2f getAverageFlow();
ofVec2f getFlowOffset(int x, int y);
ofVec2f getFlowPosition(int x, int y);
ofVec2f getTotalFlowInRegion(ofRectangle region);
ofVec2f getAverageFlowInRegion(ofRectangle region);
glm::vec2 getTotalFlow();
glm::vec2 getAverageFlow();
glm::vec2 getFlowOffset(int x, int y);
glm::vec2 getFlowPosition(int x, int y);
glm::vec2 getTotalFlowInRegion(ofRectangle region);
glm::vec2 getAverageFlowInRegion(ofRectangle region);

//call this if you switch to a new video file to reset internal caches
void resetFlow();
Expand Down
65 changes: 60 additions & 5 deletions addons/ofxCv/libs/ofxCv/include/ofxCv/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ namespace ofxCv {
void drawMat(const cv::Mat& mat, float x, float y, float width, float height);

template <class T>
ofVec2f findMaxLocation(const T& img) {
glm::vec2 findMaxLocation(const T& img) {
cv::Mat mat = toCv(img);
double minVal, maxVal;
cv::Point minLoc, maxLoc;
minMaxLoc(mat, &minVal, &maxVal, &minLoc, &maxLoc);
return ofVec2f(maxLoc.x, maxLoc.y);
return glm::vec2(maxLoc.x, maxLoc.y);
}

template <class T>
Expand Down Expand Up @@ -165,9 +165,10 @@ namespace ofxCv {
cv::Point3_<T> intersectPointRay(cv::Point3_<T> point, cv::Point3_<T> ray) {
return ray * (point.dot(ray) / ray.dot(ray));
}
// morphological thinning, also called skeletonization, strangely missing from opencv
// here is a description of the algorithm http://homepages.inf.ed.ac.uk/rbf/HIPR2/thin.htm
// Note: it may produce wrong skeletons for some complex shapes.
template <class T>
void thin(T& img) {
cv::Mat mat = toCv(img);
Expand All @@ -193,7 +194,59 @@ namespace ofxCv {
for(int i=0;i<n;i++){int j=q[i];if(!p[j+ic2]&&!p[j+ic1]&&!p[j+ib1]&&p[j+ia2]&&p[j+ib3]){p[j]=0;}}
for(int i=0;i<n;i++){int j=q[i];if(!p[j+ib1]&&!p[j+ia1]&&!p[j+ia2]&&p[j+ic2]&&p[j+ib3]){p[j]=0;}}
}

//same as above, different implementation taken from
//http://felix.abecassis.me/2011/09/opencv-morphological-skeleton/
template <class T>
void thin2(T& img) {

cv::Mat mat = toCv(img);
cv::Mat skel(mat.size(), CV_8UC1, cv::Scalar(0));
cv::Mat temp;
cv::Mat eroded;

cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));
bool done;
do{
cv::erode(mat, eroded, element);
cv::dilate(eroded, temp, element);
cv::subtract(mat, temp, temp);
cv::bitwise_or(skel, temp, skel);
eroded.copyTo(mat);
done = (cv::countNonZero(mat) == 0);
} while (!done);
skel.copyTo(mat);
return;
}

// Code for thinning a binary image using Zhang-Suen algorithm.
// Large areas to skeletonize may take considerable amount of time.
// Consider to rescale the input image and then upscale the skeleton for being computed every update()
// Otherwise use ofxCv::thin(), although it may lead to wrong skeletons for some shapes.
// Note: do not call thinningIteration() directly from your ofApp.
void thinningIteration( cv::Mat & img, int iter, cv::Mat & marker );
template<class T>
void thinning(T& img)
{
cv::Mat dst = toCv(img);
dst /= 255;
cv::Mat prev = cv::Mat::zeros(dst.size(), CV_8UC1);
cv::Mat marker = cv::Mat::zeros(dst.size(), CV_8UC1); // Re-uses allocated memory
cv::Mat diff;

do {
marker.setTo(cv::Scalar(0));
thinningIteration(dst, 0, marker);
marker.setTo(cv::Scalar(0));
thinningIteration(dst, 1, marker);
cv::absdiff(dst, prev, diff);
dst.copyTo(prev);
}
while (cv::countNonZero(diff) > 0);

dst *= 255;
}

// given a vector of lines, this function will find the average angle
float weightedAverageAngle(const std::vector<cv::Vec4i>& lines);

Expand All @@ -203,6 +256,7 @@ namespace ofxCv {
template <class S, class T, class D>
float autorotate(const S& src, D& dst, float threshold1 = 50, float threshold2 = 200) {
cv::Mat thresh;
cv::Mat srcMat = toCv(src);
cv::Canny(src, thresh, threshold1, threshold2);
return autorotate(src, thresh, dst);
}
Expand All @@ -223,9 +277,10 @@ namespace ofxCv {
rotate(src, dst, rotationAmount);
return rotationAmount;
}


// approximates a polygonal curve(s) with the specified precision.
std::vector<cv::Point2f> getConvexPolygon(const std::vector<cv::Point2f>& convexHull, int targetPoints);
static const ofColor cyanPrint = ofColor::fromHex(0x00abec);
static const ofColor magentaPrint = ofColor::fromHex(0xec008c);
static const ofColor yellowPrint = ofColor::fromHex(0xffee00);
Expand Down
10 changes: 5 additions & 5 deletions addons/ofxCv/libs/ofxCv/include/ofxCv/Kalman.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ namespace ofxCv {
// smoothness, rapidness: smaller is more smooth/rapid
// bUseAccel: set true to smooth out velocity
void init(T smoothness = 0.1, T rapidness = 0.1, bool bUseAccel = false);
void update(const ofVec3f&);
ofVec3f getPrediction();
ofVec3f getEstimation();
ofVec3f getVelocity();
void update(const glm::vec3&);
glm::vec3 getPrediction();
glm::vec3 getEstimation();
glm::vec3 getVelocity();
};

typedef KalmanPosition_<float> KalmanPosition;

// Kalman filter for orientation
template <class T>
class KalmanEuler_ : public KalmanPosition_<T> {
ofVec3f eulerPrev; // used for finding appropriate dimension
glm::vec3 eulerPrev; // used for finding appropriate dimension
public:
void init(T smoothness = 0.1, T rapidness = 0.1, bool bUseAccel = false);
void update(const ofQuaternion&);
Expand Down
10 changes: 6 additions & 4 deletions addons/ofxCv/libs/ofxCv/include/ofxCv/Tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace ofxCv {
:lastSeen(old.lastSeen)
,label(old.label)
,age(old.age)
,index(-1)
,index(old.index)
,object(old.object){
}
void timeStep(bool visible) {
Expand Down Expand Up @@ -116,10 +116,12 @@ namespace ofxCv {
std::vector<unsigned int> currentLabels, previousLabels, newLabels, deadLabels;
std::map<unsigned int, TrackedObject<T>*> previousLabelMap, currentLabelMap;

unsigned int persistence, curLabel;
unsigned int persistence;
unsigned long long curLabel;
float maximumDistance;
unsigned int getNewLabel() {
return curLabel++;
unsigned long long getNewLabel() {
curLabel++;
return curLabel;
}

public:
Expand Down
17 changes: 9 additions & 8 deletions addons/ofxCv/libs/ofxCv/include/ofxCv/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#include "ofRectangle.h"
#include "ofTexture.h"
#include "ofPixels.h"

#include "ofVideoBaseTypes.h"
#include "ofVideoPlayer.h"
#include "ofVideoGrabber.h"
#include "ofPolyline.h"
#include "ofVectorMath.h"

#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/calib3d/calib3d_c.h"
namespace ofxCv {
// these functions are for accessing Mat, ofPixels and ofImage consistently.
// they're very important for imitate().
Expand Down Expand Up @@ -257,12 +258,12 @@ namespace ofxCv {
}

cv::Mat toCv(ofMesh& mesh);
cv::Point2f toCv(ofVec2f vec);
cv::Point3f toCv(ofVec3f vec);
cv::Point2f toCv(glm::vec2 vec);
cv::Point3f toCv(glm::vec3 vec);
cv::Rect toCv(ofRectangle rect);
std::vector<cv::Point2f> toCv(const ofPolyline& polyline);
std::vector<cv::Point2f> toCv(const std::vector<ofVec2f>& points);
std::vector<cv::Point3f> toCv(const std::vector<ofVec3f>& points);
std::vector<cv::Point2f> toCv(const std::vector<glm::vec2>& points);
std::vector<cv::Point3f> toCv(const std::vector<glm::vec3>& points);
cv::Scalar toCv(ofColor color);

// cross-toolkit, cross-bitdepth copying
Expand Down Expand Up @@ -318,8 +319,8 @@ namespace ofxCv {
}

// toOf functions
ofVec2f toOf(cv::Point2f point);
ofVec3f toOf(cv::Point3f point);
glm::vec2 toOf(cv::Point2f point);
glm::vec3 toOf(cv::Point3f point);
ofRectangle toOf(cv::Rect rect);
ofPolyline toOf(cv::RotatedRect rect);
template <class T> inline ofPolyline toOf(const std::vector<cv::Point_<T>>& contour) {
Expand Down
Loading

0 comments on commit fb8c23d

Please sign in to comment.