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
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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);

+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ namespace ArmorDetection {

} // namespace ArmorDetection

using ArmorDetection::ArmorDetectionApp;
using ArmorDetection::ImgArmorDetectionApp;
using ArmorDetection::VideoArmorDetectionApp;
using ArmorDetection::BarColor;
+13 −17
Original line number Diff line number Diff line
@@ -38,24 +38,20 @@ bool Detector::target(const Mat &frame, Point &targetCenter) {

void Detector::hsv(const Mat &frame, Mat &lightArea, Mat &haloArea) {
    Mat hsvFrame;
    if (color == BarColor::BLUE) {
        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);
        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);
}


+23 −14
Original line number Diff line number Diff line
#include <iostream>
#include <memory>
#include "ArmorDetectionApp.h"

typedef std::unique_ptr<ArmorDetectionApp> Ptr;

int main(int argc, char **argv) {
    Ptr app;

//    ImgArmorDetectionApp app(
    try {
//        app = Ptr(new ImgArmorDetectionApp(
//                BarColor::BLUE,
//                cv::Size(640, 480),
//            "/home/jeeken/Pictures/blue_dark",
//                "/home/jeeken/Pictures/blue",
//                "jpg",
//            false
//    );

    VideoArmorDetectionApp app(
//                true
//        ));
        app = Ptr(new VideoArmorDetectionApp(
                BarColor::BLUE,
                cv::Size(640, 480),
                "/home/jeeken/Videos/live_blue.avi",
                false
    );
    app.run();
        ));

        app->run();
    } catch (std::exception &e) {
        std::cerr << "Sorry: " << e.what() << std::endl;
    }

    return 0;
}
 No newline at end of file