SOMS/test/XuAilibTest/LineHandle.cpp

76 lines
2.1 KiB
C++
Raw Normal View History

2024-07-15 10:31:26 +08:00
#include "LineHandle.h"
#include <iostream>
#include <SegDetector.h>
#include <NanoDetector.h>
#include <opencv2\imgproc\types_c.h>
#include<opencv2/imgproc/imgproc_c.h>
using namespace cv;
void LineHandle::crossPointsOfLines(cv::Vec4i lineA, cv::Vec4i lineB,cv::Point2f& crossPoints)
{
float ka = (float)(lineA[3]- lineA[1]) / float(lineA[2] - lineA[0]);//slope of LineA
float kb = (float)(lineB[3] - lineB[1]) / float(lineB[2]- lineB[0]);;//slope of LineB
crossPoints.x = float(ka * lineA[0] - lineA[1] - kb * lineB[0] + lineB[1]) / float(ka - kb);
crossPoints.y = float(ka * kb * (lineA[0] - lineB[1]) - kb * lineA[1] + ka * lineB[1]) / float(ka - kb);
}
bool LineHandle::comp(const Point2f& a, const Point2f& b)
{
return a.y < b.y;
}
long LineHandle::CalcMatSum( Mat img) {
//Mat MatTemp2;
//img.convertTo(MatTemp2, CV_8U);
//cv::Mat_<cv::Vec3b>::iterator it = MatTemp2.begin<cv::Vec3b>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD>ʱ֪<CAB1><D6AA>
//cv::Mat_<cv::Vec3b>::iterator itend = MatTemp2.end<cv::Vec3b>();
//long sum = 0;
//for (; it != itend; ++it)
//{
// (*it)[0] = (*it)[0];
// sum += (*it)[0];
//}
//return sum;
int channel = img.channels();
long sum = 0;
int w = img.cols;
int h = img.rows;
//uchar* uc_pixel = nullptr;
for (int row = 0; row < h; row++) {
uchar* uc_pixel = img.data + row * img.step;
int size = sizeof(uc_pixel);
for (int col = 0; col < w; col++) {
/*uc_pixel[0];*/
sum += uc_pixel[0];
uc_pixel += channel;
}
//delete uc_pixel;
}
//uc_pixel = nullptr;// uc_pixel;
return sum;
}
bool LineHandle::ComparePairFirst(std::pair<int, int> a, std::pair<int, int> b)
{
return a.first < b.first;//<2F><><EFBFBD><EFBFBD>first<73><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
bool LineHandle::ComparePairSecond(std::pair<int, int>a, std::pair<int, int> b)
{
return a.second < b.second;//<2F><><EFBFBD><EFBFBD>second<6E><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
double getDistance(CvPoint pointO, CvPoint pointA)
{
double distance;
distance = powf((pointO.x - pointA.x), 2) + powf((pointO.y - pointA.y), 2);
distance = sqrtf(distance);
return distance;
}