From 97966fb8a6012fb98b3bcf04c56b7b328bda1f06 Mon Sep 17 00:00:00 2001 From: twelve17 Date: Tue, 6 Jan 2015 14:36:24 +0000 Subject: [PATCH] Detect and use source grayscale mat if applicable. --- src/openalpr/detection/detectorcpu.cpp | 12 ++++++++++-- src/openalpr/pipeline_data.cpp | 11 +++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/openalpr/detection/detectorcpu.cpp b/src/openalpr/detection/detectorcpu.cpp index f541b2b..2775ab4 100644 --- a/src/openalpr/detection/detectorcpu.cpp +++ b/src/openalpr/detection/detectorcpu.cpp @@ -49,7 +49,15 @@ namespace alpr { Mat frame_gray; - cvtColor( frame, frame_gray, CV_BGR2GRAY ); + if (frame.channels() > 2) + { + cvtColor( frame, frame_gray, CV_BGR2GRAY ); + } + else + { + frame_gray = frame; + } + vector detectedRegions; for (int i = 0; i < regionsOfInterest.size(); i++) @@ -128,4 +136,4 @@ namespace alpr } -} \ No newline at end of file +} diff --git a/src/openalpr/pipeline_data.cpp b/src/openalpr/pipeline_data.cpp index 46dfac1..3d509c6 100644 --- a/src/openalpr/pipeline_data.cpp +++ b/src/openalpr/pipeline_data.cpp @@ -5,11 +5,18 @@ using namespace std; namespace alpr { - + PipelineData::PipelineData(Mat colorImage, Rect regionOfInterest, Config* config) { this->colorImg = colorImage; - cvtColor(this->colorImg, this->grayImg, CV_BGR2GRAY); + if (colorImage.channels() > 2) + { + cvtColor(this->colorImg, this->grayImg, CV_BGR2GRAY); + } + else + { + this->grayImg = colorImage; + } this->regionOfInterest = regionOfInterest; this->config = config;