Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add triangle function #56

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 17 additions & 0 deletions lib/src/imgproc/imgproc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:ffi' as ffi;

import 'package:ffi/ffi.dart';

import '../../opencv_dart.dart';
import '../core/contours.dart';
import '../core/scalar.dart';
import '../core/base.dart';
Expand All @@ -20,6 +21,22 @@ import '../core/termcriteria.dart';
import '../constants.g.dart';
import '../opencv.g.dart' as cvg;

List<Vec6f> getTriangles(List<Point> pts) {
final p = calloc<ffi.Pointer<cvg.Vec6f>>();
final pSize = malloc<ffi.Int>();
cvRun(() => CFFI.GetTriangles(pts.cvd.ref, p, pSize));
return List.generate(
pSize.value,
(index) => Vec6f(
p.value[index].val1,
p.value[index].val2,
p.value[index].val3,
p.value[index].val4,
p.value[index].val5,
p.value[index].val6,
));
}

rainyl marked this conversation as resolved.
Show resolved Hide resolved
/// ApproxPolyDP approximates a polygonal curve(s) with the specified precision.
///
/// For further details, please see:
Expand Down
20 changes: 20 additions & 0 deletions lib/src/opencv.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4406,6 +4406,26 @@ class CvNative {
late final _GetTickFrequency = _GetTickFrequencyPtr.asFunction<
CvStatus Function(ffi.Pointer<ffi.Double>)>();

CvStatus GetTriangles(
VecPoint points,
ffi.Pointer<ffi.Pointer<Vec6f>> rval,
ffi.Pointer<ffi.Int> size,
) {
return _GetTriangles(
points,
rval,
size,
);
}

late final _GetTrianglesPtr = _lookup<
ffi.NativeFunction<
CvStatus Function(VecPoint, ffi.Pointer<ffi.Pointer<Vec6f>>,
ffi.Pointer<ffi.Int>)>>('GetTriangles');
late final _GetTriangles = _GetTrianglesPtr.asFunction<
CvStatus Function(
VecPoint, ffi.Pointer<ffi.Pointer<Vec6f>>, ffi.Pointer<ffi.Int>)>();

CvStatus GoodFeaturesToTrack(
Mat img,
VecPoint2f corners,
Expand Down
1 change: 1 addition & 0 deletions src/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus
#include <opencv2/core.hpp>
Expand Down
37 changes: 37 additions & 0 deletions src/imgproc/imgproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,43 @@
#include <memory>
#include <vector>

Vec6f convertToVec6f(const cv::Vec6f& cvVec) {
Vec6f vec;
vec.val1 = cvVec[0];
vec.val2 = cvVec[1];
vec.val3 = cvVec[2];
vec.val4 = cvVec[3];
vec.val5 = cvVec[4];
vec.val6 = cvVec[5];
return vec;
}

CvStatus GetTriangles(VecPoint points, Vec6f **rval, int *size)
{
BEGIN_WRAP
// get convex hull from potins
// cv::convexHull(*points.ptr, *hull.ptr, clockwise, returnPoints);
cv::Mat convexHull;
cv::convexHull(*points.ptr, convexHull);
// cv::Rect r = cv::boundingRect(*pts.ptr);
cv::Rect r = cv::boundingRect(convexHull);
cv::Subdiv2D subdiv = cv::Subdiv2D(r);
for (int i = 0; i < points.ptr->size(); i++) {
// points.ptr->at(i);
cv::Point2f pt = cv::Point2f(points.ptr->at(i).x, points.ptr->at(i).y);
subdiv.insert(pt);
}
std::vector<cv::Vec6f> triangleVec;
subdiv.getTriangleList(triangleVec);

*size = triangleVec.size();
// rval에 triangleVec 할당
*rval = new Vec6f[triangleVec.size()];
for (size_t i = 0; i < triangleVec.size(); i++) {
(*rval)[i] = convertToVec6f(triangleVec[i]);
}
END_WRAP
}
rainyl marked this conversation as resolved.
Show resolved Hide resolved
CvStatus ArcLength(VecPoint curve, bool is_closed, double *rval)
{
BEGIN_WRAP
Expand Down
1 change: 1 addition & 0 deletions src/imgproc/imgproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CVD_TYPEDEF(void, CLAHE)

CVD_TYPEDEF_PTR(CLAHE)

CvStatus GetTriangles(VecPoint points, Vec6f **rval, int *size);
CvStatus ArcLength(VecPoint curve, bool is_closed, CVD_OUT double *rval);
CvStatus ApproxPolyDP(VecPoint curve, double epsilon, bool closed, CVD_OUT VecPoint *rval);
CvStatus CvtColor(Mat src, CVD_OUT Mat dst, int code);
Expand Down