OpenCV寻找火花交叉点解决方案

  • 2019 年 12 月 23 日
  • 笔记

来源:土盐

接地装置冲击特性及土壤火花放电形貌特征研究

采用接地装置暂态特性的时域电网络模型对变电站集中接地装置与接地网互连/独立时,变电站地网上暂态电位升进行仿真计算,评估变电站地网电位升对变压器中性点的反击风险,并分别计算了两种情况下雷电流入地点(集中集中装置引下线)与变压器中性点之间的防反击安全距离,以及集中接地装置冲击阻抗的安全限值。采用感光胶片对平板电极进行了火花放电形貌特征观测试验,结合平板电极冲击试验,将土壤电离过程分为四个阶段:局部放电阶段、电离延迟阶段、贯穿电离阶段与电离恢复阶段,并研究了四个电离阶段电气参数的变化特征,分析了电极的瞬时电阻与电离过程的对应关系。对不同尺寸的单根水平接地极与接地网的火花放电形貌特征进行观测试验,研究了接地装置周围土壤中火花放电的种类与特征、放电发展过程与放电点分布规律。火花放电观测结果表明,接地极周围土壤中火花放电主要分为局部放电与树枝状放电。两种形式放电点分布规律为:局部放电的放电点较多,沿导体表面密集分布,放电强度较弱;当土壤中场强超过其临界击穿场强,局部放电就发展成为强烈的树枝放电。

我是看到下面的代码,再搜知网上的这篇论文的,愿有缘人能结合这个顺利毕业,祝好。

下面是干货代码:

#include <opencv2/opencv.hpp>  using namespace cv;  #pragma comment(lib, "opencv_world410.lib")    #include <iostream>  #include <vector>  using namespace std;      int main(void)  {      Mat frame = imread("sparks.png");        if (frame.empty())      {          cout << "Error loading image file" << endl;          return -1;      }        Mat colour_frame = frame.clone();        cvtColor(frame, frame, COLOR_BGR2GRAY);        threshold(frame, frame, 127, 255, THRESH_BINARY);        vector<Point2i> branch_locations;        // Start with the second column      for (int i = 1; i < frame.cols; i++)      {          bool lit = false;          vector<int> begin_black_regions;          vector<int> end_black_regions;            // Start with the first row          if (255 == frame.at<unsigned char>(0, i))          {              lit = true;          }          else          {              lit = false;              begin_black_regions.push_back(0);          }            // Start with the second row          for (int j = 1; j < frame.rows - 1; j++)          {              if (255 == frame.at<unsigned char>(j, i) && lit == false)              {                  lit = true;                  end_black_regions.push_back(j - 1);              }              else if (0 == frame.at<unsigned char>(j, i) && lit == true)              {                  lit = false;                  begin_black_regions.push_back(j);              }          }            // End with the last row          if (0 == frame.at<unsigned char>(frame.rows - 1, i) && lit == false)          {              end_black_regions.push_back(frame.rows - 1);          }          else if (0 == frame.at<unsigned char>(frame.rows - 1, i) && lit == true)          {              begin_black_regions.push_back(frame.rows - 1);              end_black_regions.push_back(frame.rows - 1);          }          else if (255 == frame.at<unsigned char>(frame.rows - 1, i) && lit == false)          {              end_black_regions.push_back(frame.rows - 2);          }            if(begin_black_regions.size() != end_black_regions.size())              cout << begin_black_regions.size() << " " << end_black_regions.size() << endl;            // for each black region begin/end pair          for (size_t k = 0; k < begin_black_regions.size(); k++)          {              bool found_branch = true;                for (int l = begin_black_regions[k]; l <= end_black_regions[k]; l++)              {                  if (0 == frame.at<unsigned char>(l, i - 1))                  {                      found_branch = false;                      break;                  }              }                if (found_branch == true)              {                  Point2i location(i - 1, begin_black_regions[k]);                  branch_locations.push_back(location);              }          }      }        for (size_t i = 0; i < branch_locations.size(); i++)          circle(colour_frame, branch_locations[i], 2, Scalar(255, 127, 0), 2);        imshow("frame", colour_frame);        waitKey();        return 0;  }
import cv2  import numpy    frame = cv2.imread('sparks.png')    if frame is None:      print('Error loading image')      exit()    colour_frame = frame    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)    ret, frame = cv2.threshold(frame, 127, 255, cv2.THRESH_BINARY)    rows = frame.shape[0]  cols = frame.shape[1]    branch_locations = []    # start with second column  for i in range(1, cols):      lit = False      begin_black_regions = []      end_black_regions = []        # start with first row      if 255 == frame[0, i]:          lit = True      else:          lit = False          begin_black_regions.append(0)        # start with second row      for j in range(1, rows - 1):          if 255 == frame[j, i] and lit == False:              lit = True              end_black_regions.append(j - 1)          elif 0 == frame[j, i] and lit == True:              lit = False              begin_black_regions.append(j)        # end with last row      if 0 == frame[rows - 1, i] and lit == False:          end_black_regions.append(rows - 1)      elif 0 == frame[rows - 1, i] and lit == True:          begin_black_regions.append(rows - 1)          end_black_regions.append(rows - 1)      elif 255 == frame[rows - 1, i] and lit == False:          end_black_regions.append(rows - 2)        for k in range(0, len(begin_black_regions)):          found_branch = True            for l in range(begin_black_regions[k], end_black_regions[k] + 1):              if 0 == frame[l, i - 1]:                  found_branch = False                  break            if found_branch == True:              branch_locations.append(complex(i - 1, begin_black_regions[k]))    for i in range(0, len(branch_locations)):      cv2.circle(colour_frame, (int(branch_locations[i].real), int(branch_locations[i].imag)), 2, (255, 127, 0), 2)    cv2.imshow("Frame", colour_frame)    cv2.waitKey(0)