Skip to content

Commit

Permalink
draw_contours edited
Browse files Browse the repository at this point in the history
  • Loading branch information
Romaisaa committed Mar 24, 2023
1 parent 87ace93 commit d2beeb3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions CV/snake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,13 @@ double snake::calculate_contour_perimeter(vector<Point> snake_points)
return distance_sum;
}

void snake::draw_contours(Mat image, Mat &outputimage, vector<Point> snake_points,QLabel*label){
void snake::draw_contours(Mat image, Mat &outputimage, vector<Point> snake_points){
outputimage = image.clone();
for (int i = 0; i < snake_points.size(); i++) {
circle(outputimage, snake_points[i], 4, Scalar(0, 0, 255), -1);

if (i > 0) {
line(outputimage, snake_points[i-1], snake_points[i], Scalar(255, 0, 0), 2);
}
QImage qimage(outputimage.data, outputimage.cols, outputimage.rows,outputimage.step,QImage::Format_BGR888);
QPixmap* image = new QPixmap(QPixmap::fromImage(qimage));
int w = label->width();
int h = label->height();
label->setPixmap(image->scaled(w,h,Qt::KeepAspectRatio));
}
line(outputimage, snake_points[0], snake_points[snake_points.size()-1], Scalar(255, 0, 0), 2);
}
Expand All @@ -165,8 +159,12 @@ vector<Point> snake::active_contour(Mat inputimage, Mat &outputimage,
// Iterate for multiple iterations
for (int i = 0; i < numOfIterations; i++) {
snake_operation(grayimage, curve, window_size, alpha, beta, gamma);
draw_contours(inputimage, outputimage, curve,label);

draw_contours(inputimage, outputimage, curve);
QImage qimage(outputimage.data, outputimage.cols, outputimage.rows,outputimage.step,QImage::Format_BGR888);
QPixmap* image = new QPixmap(QPixmap::fromImage(qimage));
int w = label->width();
int h = label->height();
label->setPixmap(image->scaled(w,h,Qt::KeepAspectRatio));
}

// draw_contours(inputimage, outputimage, curve);
Expand Down
2 changes: 1 addition & 1 deletion CV/snake.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class snake
static double calculate_point_enegy(Mat image, Point point, Point previousPoint, Point nextPoint, double alpha, double beta, double gamma);

static void snake_operation(Mat image, vector<Point>& curve, int window_size, double alpha, double beta, double gamma);
static void draw_contours(Mat image, Mat &outputimage, vector<Point> snake_points,QLabel * label);
static void draw_contours(Mat image, Mat &outputimage, vector<Point> snake_points);
};

#endif // SNAKE_H

0 comments on commit d2beeb3

Please sign in to comment.