Skip to content

Commit

Permalink
Merge pull request #95 from Digitelektro/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Digitelektro authored Nov 19, 2023
2 parents bda5d19 + 2b6919e commit c45dd56
Show file tree
Hide file tree
Showing 22 changed files with 1,866 additions and 426 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5)
include(ExternalProject)

project(meteordemod
VERSION 2.6.1
VERSION 2.6.2
LANGUAGES CXX
)

Expand Down Expand Up @@ -52,6 +52,7 @@ ExternalProject_Add(libcorrect
)

find_package(OpenCV)
find_package(OpenCL)

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

add_executable(meteordemod
main.cpp
imageproc/spreadimage.cpp
imageproc/threatimage.cpp
imageproc/projectimage.cpp
imageproc/blendimages.cpp
imageproc/tps.cpp
decoder/correlation.cpp
decoder/reedsolomon.cpp
decoder/viterbi.cpp
Expand All @@ -83,6 +86,7 @@ add_executable(meteordemod
tools/databuffer.cpp
tools/iniparser.cpp
tools/threadpool.cpp
tools/opencl.cpp
GIS/shapereader.cpp
GIS/shaperenderer.cpp
GIS/dbfilereader.cpp
Expand Down Expand Up @@ -119,6 +123,12 @@ target_include_directories(meteordemod PUBLIC
add_dependencies(meteordemod sgp4)
add_dependencies(meteordemod libcorrect)

if(OpenCL_FOUND)
target_compile_definitions(meteordemod PUBLIC OPENCL_FOUND=1)
include_directories(${OpenCL_INCLUDE_DIRS})
target_link_libraries(meteordemod ${OpenCL_LIBRARIES})
endif()

if(WIN32)
target_link_libraries(meteordemod
${OpenCV_LIBS}
Expand Down
18 changes: 18 additions & 0 deletions GIS/shapereader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <iostream>
#include <iterator>
#include <limits>
#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -170,6 +171,10 @@ class ShapeReader {
pointBuffer.valueAtIndex(index, y, LittleEndian);
}

bool operator==(const Point& rhs) {
return (std::abs(x - rhs.x) <= std::numeric_limits<double>::epsilon()) && (std::abs(y - rhs.y) <= std::numeric_limits<double>::epsilon());
}

double x;
double y;
};
Expand Down Expand Up @@ -235,6 +240,19 @@ class ShapeReader {
return *this;
}
}
PolyLineIterator operator++(int) {
auto temp = *this;
if(mNumberOfPoint < mPolyLineHeader.numberOfpoints) {
DataBuffer pointBuffer(16);
mInputStream.read(reinterpret_cast<char*>(pointBuffer.buffer()), pointBuffer.size());
point = Point(pointBuffer);
mNumberOfPoint++;
} else {
mNumberOfPoint = 0;
point = Point();
}
return temp;
}

PolyLineIterator begin() {
int filePosition = mRecordPosition + 12; // Recordpos + Recordheader
Expand Down
41 changes: 41 additions & 0 deletions GIS/shaperenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ void GIS::ShapeRenderer::drawShape(const cv::Mat& src, Transform_t transform) {
for(polyLineIterator->begin(); *polyLineIterator != polyLineIterator->end(); ++(*polyLineIterator)) {
if(transform(polyLineIterator->point.y, polyLineIterator->point.x)) {
polyLines.push_back(cv::Point2d(polyLineIterator->point.y, polyLineIterator->point.x));
} else {
if(polyLines.size() > 1) {
cv::polylines(src, polyLines, false, mColor, mThicknes);
polyLines.clear();
}
}
}

Expand All @@ -45,6 +50,42 @@ void GIS::ShapeRenderer::drawShape(const cv::Mat& src, Transform_t transform) {
}
}
}
} else if(getShapeType() == ShapeReader::ShapeType::stPolygon) {
auto recordIterator = getRecordIterator();

if(recordIterator) {
for(recordIterator->begin(); *recordIterator != recordIterator->end(); ++(*recordIterator)) {
auto polyLineIterator = getPolyLineIterator(*recordIterator);

if(polyLineIterator) {
bool isFirst = true;
ShapeReader::Point first;
std::vector<cv::Point> polyLines;
for(polyLineIterator->begin(); *polyLineIterator != polyLineIterator->end(); ++(*polyLineIterator)) {
if(!isFirst && (first == polyLineIterator->point)) {
if(polyLines.size() > 1) {
cv::polylines(src, polyLines, false, mColor, mThicknes);
}
isFirst = true;
polyLines.clear();
continue;
}
if(isFirst) {
first = polyLineIterator->point;
isFirst = false;
}
if(transform(polyLineIterator->point.y, polyLineIterator->point.x)) {
polyLines.push_back(cv::Point2d(polyLineIterator->point.y, polyLineIterator->point.x));
} else {
if(polyLines.size() > 1) {
cv::polylines(src, polyLines, false, mColor, mThicknes);
polyLines.clear();
}
}
}
}
}
}
} else if(getShapeType() == ShapeReader::ShapeType::stPoint) {
auto recordIterator = getRecordIterator();

Expand Down
110 changes: 110 additions & 0 deletions imageproc/blendimages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include "blendimages.h"

cv::Mat BlendImages::merge(std::list<cv::Mat>& images) {
std::list<cv::Mat>::iterator it = images.begin();

cv::Mat composite = it->clone();
++it;

composite.convertTo(composite, CV_32FC3);

for(; it != images.end(); ++it) {
it->convertTo(*it, CV_32FC3);

cv::Mat grayScale1;
cv::Mat alpha1;
cv::medianBlur(composite, grayScale1, 5);
cv::cvtColor(grayScale1, grayScale1, cv::COLOR_BGR2GRAY);

cv::threshold(grayScale1, alpha1, 0, 255, cv::THRESH_BINARY);
grayScale1.release();

cv::Mat grayScale2;
cv::Mat alpha2;
cv::medianBlur(*it, grayScale2, 5);
cv::cvtColor(grayScale2, grayScale2, cv::COLOR_BGR2GRAY);

cv::threshold(grayScale2, alpha2, 0, 255, cv::THRESH_BINARY);
grayScale2.release();

cv::Mat mask;
cv::bitwise_and(alpha1, alpha2, mask);
alpha1.release();
alpha2.release();

std::vector<cv::Mat> channels;
channels.push_back(mask);
channels.push_back(mask);
channels.push_back(mask);
cv::merge(channels, mask);

mask.convertTo(mask, CV_32FC3, 1 / 255.0);

int start0 = findImageStart(composite);
int start1 = findImageStart(*it);
bool leftToRight = start0 < start1;

cv::Mat blendmask = blendMask(mask, leftToRight);
cv::multiply(cv::Scalar::all(1.0) - blendmask, composite, composite);
blendmask = blendMask(mask, !leftToRight);
cv::multiply(cv::Scalar::all(1.0) - blendmask, *it, *it);

cv::add(composite, *it, composite);
}

return composite;
}

int BlendImages::findImageStart(const cv::Mat& img) {
int i = img.size().width;
for(int y = 0; y < img.size().height; ++y) {
for(int x = 0; x < img.size().width; x++) {
if(img.at<cv::Vec3f>(y, x) != cv::Vec3f(0, 0, 0)) {
if(x < i) {
i = x;
}
}
}
}
return i;
}

cv::Mat BlendImages::blendMask(const cv::Mat& mask, bool leftToRight) {
int xStart = 0;
int xEnd = 0;
int blendWidth = 0;
float alpha;

cv::Mat blendedMask = cv::Mat::zeros(mask.size().height, mask.size().width, mask.type());

for(int y = 0; y < mask.size().height; ++y) {
bool foundStart = false;
bool foundEnd = false;
for(int x = 0; x < mask.size().width; x++) {
if(!foundStart && mask.at<cv::Vec3f>(y, x) != cv::Vec3f(0, 0, 0)) {
foundStart = true;
xStart = x;

for(int temp = x; temp < mask.size().width; temp++) {
if(mask.at<cv::Vec3f>(y, temp) != cv::Vec3f(1, 1, 1)) {
xEnd = temp;
foundEnd = true;
blendWidth = xEnd - xStart;
break;
}
}
}

if(foundStart && foundEnd && (x >= xStart && x <= xEnd)) {
alpha = static_cast<float>(x - xStart) / blendWidth;
alpha = leftToRight ? alpha : 1.0f - alpha;

blendedMask.at<cv::Vec3f>(y, x) = mask.at<cv::Vec3f>(y, x) * alpha;
} else if(foundStart && foundEnd && (x > xEnd)) {
foundStart = false;
foundEnd = false;
}
}
}
return blendedMask;
}
13 changes: 13 additions & 0 deletions imageproc/blendimages.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <list>
#include <opencv2/imgproc.hpp>

class BlendImages {
public:
static cv::Mat merge(std::list<cv::Mat>& images);

private:
static int findImageStart(const cv::Mat& img);
static cv::Mat blendMask(const cv::Mat& mask, bool leftToRight);
};
Loading

0 comments on commit c45dd56

Please sign in to comment.