aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TCC/Tango.TCC.OpenCV/BhBlocks.cpp
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-03-26 12:54:09 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-03-26 12:54:09 +0200
commit7dbd32ddcf6611dec88ef56336b364110b019571 (patch)
tree9cb2ed657787d907b6bbd7695aafa244bba886ee /Software/Visual_Studio/TCC/Tango.TCC.OpenCV/BhBlocks.cpp
parent0aaf60dbc0322abc6707b5cf057d797fc26a1734 (diff)
downloadTango-7dbd32ddcf6611dec88ef56336b364110b019571.tar.gz
Tango-7dbd32ddcf6611dec88ef56336b364110b019571.zip
A lot of work !!!!
Diffstat (limited to 'Software/Visual_Studio/TCC/Tango.TCC.OpenCV/BhBlocks.cpp')
-rw-r--r--Software/Visual_Studio/TCC/Tango.TCC.OpenCV/BhBlocks.cpp196
1 files changed, 196 insertions, 0 deletions
diff --git a/Software/Visual_Studio/TCC/Tango.TCC.OpenCV/BhBlocks.cpp b/Software/Visual_Studio/TCC/Tango.TCC.OpenCV/BhBlocks.cpp
new file mode 100644
index 000000000..6d2daa7be
--- /dev/null
+++ b/Software/Visual_Studio/TCC/Tango.TCC.OpenCV/BhBlocks.cpp
@@ -0,0 +1,196 @@
+#include "BhBlocks.h"
+#include "opencv2/core/core.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/highgui/highgui.hpp"
+
+using namespace cv;
+using namespace std;
+
+void BhBlocks::setColsRowsCount(int colCount, int rowCount)
+{
+ this->colSize = -1;
+ this->rowSize = -1;
+ this->colCount = colCount;
+ this->rowCount = rowCount;
+
+}
+
+void BhBlocks::setColRowSize(float colSize, float rowSize)
+{
+ this->colCount = -1;
+ this->rowCount = -1;
+ this->colSize = colSize;
+ this->rowCount = rowCount;
+ compute();
+
+}
+
+void BhBlocks::setRect(IplImage* srcImage)
+{
+ rct = cvGetImageROI(srcImage);
+ compute();
+}
+
+void BhBlocks::setRect(const CvRect& srcRect)
+{
+ rct = srcRect;
+ compute();
+}
+
+int BhBlocks::getColCount()
+{
+ return colCount;
+}
+
+int BhBlocks::getRowCount()
+{
+ return rowCount;
+}
+
+float BhBlocks::getColSize()
+{
+ return colSize;
+}
+
+float BhBlocks::getRowSize()
+{
+ return rowSize;
+}
+BhBlocks::BhBlocks(const IplImage* srcImage, float colSize, float rowSize, int colCount, int rowCount)
+{
+ rct = cvGetImageROI(srcImage);
+ this->colCount = colCount;
+ this->rowCount = rowCount;
+ if (colSize == -1 && colSize == -1)
+ return;
+ if (rowSize == -1)
+ rowSize = colSize;
+
+ this->colSize = colSize;
+ this->rowSize = rowSize;
+ compute();
+
+}
+
+BhBlocks::BhBlocks(const Mat& srcMat, float colSize, float rowSize, int colCount, int rowCount)
+{
+ rct.x = 0;
+ rct.y = 0;
+ rct.width = srcMat.cols;
+ rct.height = srcMat.rows;
+
+ this->colCount = colCount;
+ this->rowCount = rowCount;
+ if (colSize == -1 && colSize == -1 && colCount == -1 && rowCount == -1)
+ return;
+ if (rowSize == -1)
+ rowSize = colSize;
+
+ this->colSize = colSize;
+ this->rowSize = rowSize;
+ compute();
+}
+
+BhBlocks::BhBlocks(const CvRect& srcRect, float colSize, float rowSize, int colCount, int rowCount)
+{
+ rct = srcRect;
+ this->colCount = colCount;
+ this->rowCount = rowCount;
+ if (colSize == -1 && colSize == -1)
+ return;
+ if (rowSize == -1)
+ rowSize = colSize;
+
+ this->colSize = colSize;
+ this->rowSize = rowSize;
+ compute();
+}
+
+
+
+void BhBlocks::compute()
+{
+
+
+ float cSize;
+ float rSize;
+ if (colSize != -1 && rowSize != -1)
+ {
+ colCount = int(rct.width / colSize);
+ rowCount = int(rct.height / rowSize);
+
+ cSize = (float)rct.width / colCount;
+ rSize = (float)rct.height / rowCount;
+ }
+ else if (colCount != -1 && rowCount != -1)
+ {
+ colSize = (float)rct.width / colCount;
+ rowSize = (float)rct.height / rowCount;
+ cSize = colSize;
+ rSize = rowSize;
+
+ }
+ else return;
+ rects.clear();
+ rects.resize(rowCount);
+ for (int i = 0; i < rowCount; i++)
+ rects[i].resize(colCount);
+
+ float sumCol = 0;
+
+ for (int j = 0; j < colCount; j++)
+ {
+ float newSumCol = sumCol + cSize;
+ float curColSize = int(newSumCol - int(sumCol));
+ for (int i = 0; i < rowCount; i++)
+ {
+ rects[i][j].width = curColSize;
+ rects[i][j].x = sumCol;
+ }
+ sumCol = newSumCol;
+
+ }
+
+ float sumRow = 0;
+ for (int i = 0; i < rowCount; i++)
+ {
+ float newSumRow = sumRow + rSize;
+ float curRowSize = int(newSumRow - int(sumRow));
+ for (int j = 0; j < colCount; j++)
+ {
+ rects[i][j].height = curRowSize;
+ rects[i][j].y = sumRow;
+ }
+
+ sumRow = newSumRow;
+ }
+
+}
+void BhBlocks::drawBlocks(Mat srcImage, Scalar color, int thickness)
+{
+ for (int i = 0; i < rowCount; i++)
+ for (int j = 0; j < colCount; j++)
+ rectangle(srcImage, rects[i][j], color);
+}
+
+vector<Rect> BhBlocks::getRects()
+{
+ vector<Rect> result;
+
+ for (int i = 0; i < rowCount; i++)
+ for (int j = 0; j < colCount; j++)
+ result.push_back(rects[i][j]);
+
+ return result;
+}
+
+
+void BhBlocks::displayBlocks(char* title, IplImage* srcImage, CvScalar color, int thickness)
+{
+ //IplImage* viewImg = cvCloneImage(srcImage);
+ //drawBlocks(viewImg, color, thickness);
+ //cvShowImage(title, viewImg);
+ //cvWaitKey(0);
+ //cvDestroyWindow(title);
+ //cvReleaseImage(&viewImg);
+} \ No newline at end of file