CCIMXDesktop
 
Loading...
Searching...
No Matches
ContoursQueryProc.h
1#ifndef CONTOURSQUERYPROC_H
2#define CONTOURSQUERYPROC_H
3
4#include "CannyProcessor.h"
5#include "image_proc_base.h"
6#include <map>
7#include <stdexcept>
8#include <string>
9#include <vector>
10
14namespace Processor {
15
19namespace ContoursQuery {
20
32
36 static constexpr Method DEF = Method::CHAIN_APPROX_SIMPLE;
37
41 const std::map<std::string, Method> mappings = {
42 { "ALL_POINT(CHAIN_APPROX_NONE)", Method::CHAIN_APPROX_NONE },
43 { "LINE(CHAIN_APPROX_SIMPLE)", Method::CHAIN_APPROX_SIMPLE },
44 { "L1(CHAIN_APPROX_TC89_L1)", Method::CHAIN_APPROX_TC89_L1 },
45 { "KCOS(CHAIN_APPROX_TC89_KCOS)", Method::CHAIN_APPROX_TC89_KCOS }
46 };
47
52 static const std::string DEF_STR() {
53 for (const auto& it : mappings) {
54 if (it.second == DEF) {
55 return it.first;
56 }
57 }
58 return "";
59 }
60
65 static const std::vector<std::string> keys() {
66 std::vector<std::string> result;
67 for (const auto& it : mappings) {
68 result.emplace_back(it.first);
69 }
70 return result;
71 }
72
79 static const Method fromString(const std::string& from_name) {
80 auto it = mappings.find(from_name);
81 if (it == mappings.end()) {
82 throw std::invalid_argument("Invalid name");
83 }
84 return it->second;
85 }
86
87} // namespace ContoursQuery
88
89} // namespace Processor
90
98public:
102 ContoursQueryProc() = default;
103
107 ~ContoursQueryProc() override = default;
108
114 bool process(CVImage& prev_image) override;
115
120 inline void setCannyPackage(const std::pair<int, int>& p) {
121 canny_processor.threholds_pair = p;
122 }
123
127 Processor::ContoursQuery::Method method { Processor::ContoursQuery::DEF };
128
129private:
133 CannyProcessor canny_processor;
134};
135
136#endif // CONTOURSQUERYPROC_H
The CVImage class is the image class that provides the image in the frameworks.
Definition CVImage.h:9
CannyProcessor process Canny lol.
Definition CannyProcessor.h:25
std::pair< int, int > threholds_pair
pair controller
Definition CannyProcessor.h:43
The ContoursQueryProc class performs edge detection followed by contour detection.
Definition ContoursQueryProc.h:97
void setCannyPackage(const std::pair< int, int > &p)
Sets the Canny threshold pair used in edge detection.
Definition ContoursQueryProc.h:120
Processor::ContoursQuery::Method method
The contour approximation method used for this processor.
Definition ContoursQueryProc.h:127
~ContoursQueryProc() override=default
Destructor.
bool process(CVImage &prev_image) override
Processes the image using Canny edge detection followed by contour detection.
Definition ContoursQueryProc.cpp:4
ContoursQueryProc()=default
Constructs a ContoursQueryProc with default method and Canny processor.
Method
Enumeration of different contour approximation methods.
Definition ContoursQueryProc.h:26
@ CHAIN_APPROX_TC89_KCOS
Teh-Chin approximation algorithm (K-cosine).
@ CHAIN_APPROX_NONE
All points are stored.
@ CHAIN_APPROX_SIMPLE
Compresses horizontal, vertical, and diagonal segments.
@ CHAIN_APPROX_TC89_L1
Teh-Chin approximation algorithm (L1).
const std::map< std::string, Method > mappings
String-to-enum mapping for contour approximation methods.
Definition ContoursQueryProc.h:41
The Processor namespace contains different image processing categories.
base of all processors
Definition image_proc_base.h:8