Commit 9dce0bcf authored by Jeeken's avatar Jeeken
Browse files

fix red mode

it has the same ideal performance for blue and red mode now
parent 38d2005a
......@@ -72,7 +72,7 @@ void VideoArmorDetectionApp::run() {
cv::imshow(std::get<0>(debugInfo), std::get<1>(debugInfo));
if (hasTarget) {
std::cout << "Target: " << target << std::endl;
std::cout << "Target: " << target << std::endl;
cv::circle(frame, target, 4, MarkerBgrColor::GREEN, -1);
} else {
std::cout << "No Target" << std::endl;
......@@ -81,11 +81,11 @@ void VideoArmorDetectionApp::run() {
bool hasValidTarget = smoother.smooth(hasTarget, target);
if (hasValidTarget) {
ArmorDetectionApp::drawTarget(frame, target);
std::cout << "Smoothed: " << target << std::endl;
std::cout << "Valid Target: " << target << std::endl;
} else {
std::cout << "No Smoothed" << std::endl;
std::cout << "No Valid Target" << std::endl;
}
std::cout << "--------------------" << std::endl;
std::cout << "------------------------" << std::endl;
cv::imshow("Aimed", frame);
......
......@@ -55,6 +55,7 @@ namespace ArmorDetection {
} // namespace ArmorDetection
using ArmorDetection::ArmorDetectionApp;
using ArmorDetection::ImgArmorDetectionApp;
using ArmorDetection::VideoArmorDetectionApp;
using ArmorDetection::BarColor;
......
......@@ -38,24 +38,20 @@ bool Detector::target(const Mat &frame, Point &targetCenter) {
void Detector::hsv(const Mat &frame, Mat &lightArea, Mat &haloArea) {
Mat hsvFrame;
cv::cvtColor(frame, hsvFrame, cv::COLOR_BGR2HSV);
if (color == BarColor::RED) {
Mat hsvSpace[3];
cv::split(hsvFrame, hsvSpace);
Mat &h = hsvSpace[0];
h += 107;
h -= (h / 180) * 180;
cv::merge(hsvSpace, 3, hsvFrame);
addDebugImg("Red2Blue", hsvFrame);
if (color == BarColor::BLUE) {
cv::cvtColor(frame, hsvFrame, cv::COLOR_BGR2HSV);
Scalar lowerBlueLight(90, 0, 200), upperBlueLight(120, 180, 255);
Scalar lowerBlueHalo(90, 120, 185), upperBlueHalo(120, 255, 255);
cv::inRange(hsvFrame, lowerBlueLight, upperBlueLight, lightArea);
cv::inRange(hsvFrame, lowerBlueHalo, upperBlueHalo, haloArea);
} else { // For BarColor::RED
// cheat openCV: swap Red and Blue channels implicitly
cv::cvtColor(frame, hsvFrame, cv::COLOR_RGB2HSV);
Scalar lowerBlueLight(100, 0, 200), upperBlueLight(130, 180, 255);
Scalar lowerBlueHalo(100, 120, 185), upperBlueHalo(130, 255, 255);
cv::inRange(hsvFrame, lowerBlueLight, upperBlueLight, lightArea);
cv::inRange(hsvFrame, lowerBlueHalo, upperBlueHalo, haloArea);
}
unsigned char lowerLight[3] = {90, 0, 200};
unsigned char upperLight[3] = {120, 180, 255};
unsigned char lowerHalo[3] = {90, 120, 185};
unsigned char upperHalo[3] = {120, 255, 255};
cv::inRange(hsvFrame, Mat(1, 3, CV_8UC1, lowerLight), Mat(1, 3, CV_8UC1, upperLight), lightArea);
cv::inRange(hsvFrame, Mat(1, 3, CV_8UC1, lowerHalo), Mat(1, 3, CV_8UC1, upperHalo), haloArea);
}
......
#include <iostream>
#include <memory>
#include "ArmorDetectionApp.h"
typedef std::unique_ptr<ArmorDetectionApp> Ptr;
int main(int argc, char **argv) {
Ptr app;
try {
// app = Ptr(new ImgArmorDetectionApp(
// BarColor::BLUE,
// cv::Size(640, 480),
// "/home/jeeken/Pictures/blue",
// "jpg",
// true
// ));
app = Ptr(new VideoArmorDetectionApp(
BarColor::BLUE,
cv::Size(640, 480),
"/home/jeeken/Videos/live_blue.avi",
false
));
// ImgArmorDetectionApp app(
// BarColor::BLUE,
// cv::Size(640, 480),
// "/home/jeeken/Pictures/blue_dark",
// "jpg",
// false
// );
app->run();
} catch (std::exception &e) {
std::cerr << "Sorry: " << e.what() << std::endl;
}
VideoArmorDetectionApp app(
BarColor::BLUE,
cv::Size(640, 480),
"/home/jeeken/Videos/live_blue.avi",
false
);
app.run();
return 0;
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment