Skip to content

Commit c45dd56

Browse files
authored
Merge pull request #95 from Digitelektro/develop
Develop
2 parents bda5d19 + 2b6919e commit c45dd56

22 files changed

Lines changed: 1866 additions & 426 deletions

CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5)
33
include(ExternalProject)
44

55
project(meteordemod
6-
VERSION 2.6.1
6+
VERSION 2.6.2
77
LANGUAGES CXX
88
)
99

@@ -52,6 +52,7 @@ ExternalProject_Add(libcorrect
5252
)
5353

5454
find_package(OpenCV)
55+
find_package(OpenCL)
5556

5657
link_directories(
5758
${CMAKE_BINARY_DIR}/sgp4-build/libsgp4
@@ -62,8 +63,10 @@ add_definitions(-D_USE_MATH_DEFINES -D_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATI
6263

6364
add_executable(meteordemod
6465
main.cpp
65-
imageproc/spreadimage.cpp
6666
imageproc/threatimage.cpp
67+
imageproc/projectimage.cpp
68+
imageproc/blendimages.cpp
69+
imageproc/tps.cpp
6770
decoder/correlation.cpp
6871
decoder/reedsolomon.cpp
6972
decoder/viterbi.cpp
@@ -83,6 +86,7 @@ add_executable(meteordemod
8386
tools/databuffer.cpp
8487
tools/iniparser.cpp
8588
tools/threadpool.cpp
89+
tools/opencl.cpp
8690
GIS/shapereader.cpp
8791
GIS/shaperenderer.cpp
8892
GIS/dbfilereader.cpp
@@ -119,6 +123,12 @@ target_include_directories(meteordemod PUBLIC
119123
add_dependencies(meteordemod sgp4)
120124
add_dependencies(meteordemod libcorrect)
121125

126+
if(OpenCL_FOUND)
127+
target_compile_definitions(meteordemod PUBLIC OPENCL_FOUND=1)
128+
include_directories(${OpenCL_INCLUDE_DIRS})
129+
target_link_libraries(meteordemod ${OpenCL_LIBRARIES})
130+
endif()
131+
122132
if(WIN32)
123133
target_link_libraries(meteordemod
124134
${OpenCV_LIBS}

GIS/shapereader.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <iostream>
55
#include <iterator>
6+
#include <limits>
67
#include <memory>
78
#include <string>
89
#include <vector>
@@ -170,6 +171,10 @@ class ShapeReader {
170171
pointBuffer.valueAtIndex(index, y, LittleEndian);
171172
}
172173

174+
bool operator==(const Point& rhs) {
175+
return (std::abs(x - rhs.x) <= std::numeric_limits<double>::epsilon()) && (std::abs(y - rhs.y) <= std::numeric_limits<double>::epsilon());
176+
}
177+
173178
double x;
174179
double y;
175180
};
@@ -235,6 +240,19 @@ class ShapeReader {
235240
return *this;
236241
}
237242
}
243+
PolyLineIterator operator++(int) {
244+
auto temp = *this;
245+
if(mNumberOfPoint < mPolyLineHeader.numberOfpoints) {
246+
DataBuffer pointBuffer(16);
247+
mInputStream.read(reinterpret_cast<char*>(pointBuffer.buffer()), pointBuffer.size());
248+
point = Point(pointBuffer);
249+
mNumberOfPoint++;
250+
} else {
251+
mNumberOfPoint = 0;
252+
point = Point();
253+
}
254+
return temp;
255+
}
238256

239257
PolyLineIterator begin() {
240258
int filePosition = mRecordPosition + 12; // Recordpos + Recordheader

GIS/shaperenderer.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ void GIS::ShapeRenderer::drawShape(const cv::Mat& src, Transform_t transform) {
3636
for(polyLineIterator->begin(); *polyLineIterator != polyLineIterator->end(); ++(*polyLineIterator)) {
3737
if(transform(polyLineIterator->point.y, polyLineIterator->point.x)) {
3838
polyLines.push_back(cv::Point2d(polyLineIterator->point.y, polyLineIterator->point.x));
39+
} else {
40+
if(polyLines.size() > 1) {
41+
cv::polylines(src, polyLines, false, mColor, mThicknes);
42+
polyLines.clear();
43+
}
3944
}
4045
}
4146

@@ -45,6 +50,42 @@ void GIS::ShapeRenderer::drawShape(const cv::Mat& src, Transform_t transform) {
4550
}
4651
}
4752
}
53+
} else if(getShapeType() == ShapeReader::ShapeType::stPolygon) {
54+
auto recordIterator = getRecordIterator();
55+
56+
if(recordIterator) {
57+
for(recordIterator->begin(); *recordIterator != recordIterator->end(); ++(*recordIterator)) {
58+
auto polyLineIterator = getPolyLineIterator(*recordIterator);
59+
60+
if(polyLineIterator) {
61+
bool isFirst = true;
62+
ShapeReader::Point first;
63+
std::vector<cv::Point> polyLines;
64+
for(polyLineIterator->begin(); *polyLineIterator != polyLineIterator->end(); ++(*polyLineIterator)) {
65+
if(!isFirst && (first == polyLineIterator->point)) {
66+
if(polyLines.size() > 1) {
67+
cv::polylines(src, polyLines, false, mColor, mThicknes);
68+
}
69+
isFirst = true;
70+
polyLines.clear();
71+
continue;
72+
}
73+
if(isFirst) {
74+
first = polyLineIterator->point;
75+
isFirst = false;
76+
}
77+
if(transform(polyLineIterator->point.y, polyLineIterator->point.x)) {
78+
polyLines.push_back(cv::Point2d(polyLineIterator->point.y, polyLineIterator->point.x));
79+
} else {
80+
if(polyLines.size() > 1) {
81+
cv::polylines(src, polyLines, false, mColor, mThicknes);
82+
polyLines.clear();
83+
}
84+
}
85+
}
86+
}
87+
}
88+
}
4889
} else if(getShapeType() == ShapeReader::ShapeType::stPoint) {
4990
auto recordIterator = getRecordIterator();
5091

imageproc/blendimages.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#include "blendimages.h"
2+
3+
cv::Mat BlendImages::merge(std::list<cv::Mat>& images) {
4+
std::list<cv::Mat>::iterator it = images.begin();
5+
6+
cv::Mat composite = it->clone();
7+
++it;
8+
9+
composite.convertTo(composite, CV_32FC3);
10+
11+
for(; it != images.end(); ++it) {
12+
it->convertTo(*it, CV_32FC3);
13+
14+
cv::Mat grayScale1;
15+
cv::Mat alpha1;
16+
cv::medianBlur(composite, grayScale1, 5);
17+
cv::cvtColor(grayScale1, grayScale1, cv::COLOR_BGR2GRAY);
18+
19+
cv::threshold(grayScale1, alpha1, 0, 255, cv::THRESH_BINARY);
20+
grayScale1.release();
21+
22+
cv::Mat grayScale2;
23+
cv::Mat alpha2;
24+
cv::medianBlur(*it, grayScale2, 5);
25+
cv::cvtColor(grayScale2, grayScale2, cv::COLOR_BGR2GRAY);
26+
27+
cv::threshold(grayScale2, alpha2, 0, 255, cv::THRESH_BINARY);
28+
grayScale2.release();
29+
30+
cv::Mat mask;
31+
cv::bitwise_and(alpha1, alpha2, mask);
32+
alpha1.release();
33+
alpha2.release();
34+
35+
std::vector<cv::Mat> channels;
36+
channels.push_back(mask);
37+
channels.push_back(mask);
38+
channels.push_back(mask);
39+
cv::merge(channels, mask);
40+
41+
mask.convertTo(mask, CV_32FC3, 1 / 255.0);
42+
43+
int start0 = findImageStart(composite);
44+
int start1 = findImageStart(*it);
45+
bool leftToRight = start0 < start1;
46+
47+
cv::Mat blendmask = blendMask(mask, leftToRight);
48+
cv::multiply(cv::Scalar::all(1.0) - blendmask, composite, composite);
49+
blendmask = blendMask(mask, !leftToRight);
50+
cv::multiply(cv::Scalar::all(1.0) - blendmask, *it, *it);
51+
52+
cv::add(composite, *it, composite);
53+
}
54+
55+
return composite;
56+
}
57+
58+
int BlendImages::findImageStart(const cv::Mat& img) {
59+
int i = img.size().width;
60+
for(int y = 0; y < img.size().height; ++y) {
61+
for(int x = 0; x < img.size().width; x++) {
62+
if(img.at<cv::Vec3f>(y, x) != cv::Vec3f(0, 0, 0)) {
63+
if(x < i) {
64+
i = x;
65+
}
66+
}
67+
}
68+
}
69+
return i;
70+
}
71+
72+
cv::Mat BlendImages::blendMask(const cv::Mat& mask, bool leftToRight) {
73+
int xStart = 0;
74+
int xEnd = 0;
75+
int blendWidth = 0;
76+
float alpha;
77+
78+
cv::Mat blendedMask = cv::Mat::zeros(mask.size().height, mask.size().width, mask.type());
79+
80+
for(int y = 0; y < mask.size().height; ++y) {
81+
bool foundStart = false;
82+
bool foundEnd = false;
83+
for(int x = 0; x < mask.size().width; x++) {
84+
if(!foundStart && mask.at<cv::Vec3f>(y, x) != cv::Vec3f(0, 0, 0)) {
85+
foundStart = true;
86+
xStart = x;
87+
88+
for(int temp = x; temp < mask.size().width; temp++) {
89+
if(mask.at<cv::Vec3f>(y, temp) != cv::Vec3f(1, 1, 1)) {
90+
xEnd = temp;
91+
foundEnd = true;
92+
blendWidth = xEnd - xStart;
93+
break;
94+
}
95+
}
96+
}
97+
98+
if(foundStart && foundEnd && (x >= xStart && x <= xEnd)) {
99+
alpha = static_cast<float>(x - xStart) / blendWidth;
100+
alpha = leftToRight ? alpha : 1.0f - alpha;
101+
102+
blendedMask.at<cv::Vec3f>(y, x) = mask.at<cv::Vec3f>(y, x) * alpha;
103+
} else if(foundStart && foundEnd && (x > xEnd)) {
104+
foundStart = false;
105+
foundEnd = false;
106+
}
107+
}
108+
}
109+
return blendedMask;
110+
}

imageproc/blendimages.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include <list>
4+
#include <opencv2/imgproc.hpp>
5+
6+
class BlendImages {
7+
public:
8+
static cv::Mat merge(std::list<cv::Mat>& images);
9+
10+
private:
11+
static int findImageStart(const cv::Mat& img);
12+
static cv::Mat blendMask(const cv::Mat& mask, bool leftToRight);
13+
};

0 commit comments

Comments
 (0)