Answer the question
In order to leave comments, you need to log in
How to structure the program correctly?
Good day to all! I decided to do gesture recognition, trained the classifier using traicascade, tested its work in a simple program, where it searches for a gesture in a picture. Due to the fact that the sample is not very large, the recognition accuracy is about 50 percent. Now the main question is, I will have a lot of gestures, 5-7 pieces, and I want the program to be able to sign which gesture it "saw". How to tie it all? Somehow it doesn’t reach me yet ... I am
attaching an example of a program.
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main()
{
Mat image;
image = imread("hand_gesture.jpg", CV_LOAD_IMAGE_COLOR);
namedWindow("window1", 1); imshow("window1", image);
// Load hand cascade (.xml file)
CascadeClassifier hand_cascade;
hand_cascade.load("C:\\opencv\\build\\etc\\haarcascades\\haarcascade_frontalcathand.xml");
// Detect hands
std::vector<Rect> hands;
hand_cascade.detectMultiScale(image, hands, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
// Draw circles on the detected hands
for (int i = 0; i < hands.size(); i++)
{
Point center(hands[i].x + hands[i].width*0.5, hands[i].y + hands[i].height*0.5);
ellipse(image, center, Size(hands[i].width*0.5, hands[i].height*0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
}
imshow("Detected hand", image);
waitKey(0);
return 0;
}
Answer the question
In order to leave comments, you need to log in
Play around with cv::rectangle, cv::addWeighted and cv::putText.
Here is the code straight from the working draft, draws a semi-transparent rectangle and writes lines of text:
cv::Mat writeOnImage(const cv::Mat& source, const std::vector<std::string>& lines, int width)
{
auto rect = source.clone();
cv::rectangle(rect, { 10, 10 }, { width, 20 + 50 * static_cast<int>(lines.size()) }, cv::Scalar(0, 0, 0), cv::FILLED);
auto result = cv::Mat();
cv::addWeighted(source, 0.6, rect, 0.4, 0.0, result);
for (size_t i = 0; i < lines.size(); ++i) {
cv::putText(result, lines[i], { 20, 50 + 50 * static_cast<int>(i) }, cv::FONT_HERSHEY_PLAIN, 3, cv::Scalar(10, 255, 255), 3, cv::LINE_8);
}
return result;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question