Cpp/hand&arm_detection.cpp
2026-05-17 02:56:32 +03:00

49 lines
1.1 KiB
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <opencv2/opencv.hpp>
#include <iostream>
int main() {
cv::VideoCapture cap(0);
if (!cap.isOpened()) {
std::cout << "Не удалось открыть камеру\n";
return -1;
}
cv::Mat frame, hsv, mask;
while (true) {
cap >> frame;
if (frame.empty()) break;
cv::cvtColor(frame, hsv, cv::COLOR_BGR2HSV);
cv::Scalar lower(0, 30, 60);
cv::Scalar upper(20, 150, 255);
cv::inRange(hsv, lower, upper, mask);
cv::GaussianBlur(mask, mask, cv::Size(7,7), 0);
std::vector<std::vector<cv::Point>> contours;
cv::findContours(mask, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
for (const auto &c : contours) {
if (cv::contourArea(c) > 8000) {
cv::Rect r = cv::boundingRect(c);
cv::rectangle(frame, r, cv::Scalar(255, 0, 0), 2);
}
}
cv::imshow("Hand Tracking", frame);
cv::imshow("Mask", mask);
if (cv::waitKey(1) == 27) break;
}
cap.release();
cv::destroyAllWindows();
return 0;
}