因此,我正在使用声纳图像进行图像处理项目。更具体地说,我正在尝试提取声纳扫描仪拍摄的水池图像的尺寸。我能够提取池的矩形区域,但无法弄清楚如何获得每个边缘的像素尺寸。我正在Python中使用OpenCV。
如果有人可以给我任何建议,我将不胜感激。
我已经尝试过找到hough线的线相交点,但是结果并不令人满意。
到目前为止的代码。
import cv2
import numpy as np
from scipy import ndimage as ndi
from scipy.ndimage.measurements import label
def largest_component(indices):
#this function takes a list of indices denoting
#the white regions of the image and returns the largest
#white object of connected indices
return_arr = np.zeros((512,512), dtype=np.uint8)
for index in indeces:
return_arr[index[0]][index[1]] = 255
return return_arr
image = cv2.imread('sonar_dataset/useful/sonarXY_5.bmp', 0)
image_gaussian = ndi.gaussian_filter(image, 4)
image_gaussian_inv = cv2.bitwise_not(image_gaussian)
kernel = np.ones((3,3),np.uint8)
# double thresholding extracting the sides of the …Run Code Online (Sandbox Code Playgroud) 我正在尝试修改 Kadane 算法以解决更具体的问题。
def max_Sum(arr, length, k):
if length < k:
print('length of array should be greater than k')
res = 0
for i in range(0, k):
res += arr[i]
current_sum = res
for i in range(k, n):
if k == n:
for j in range(0, k-1):
res += arr[j]
current_sum = res
else:
current_sum += arr[i] - arr[i-k]
print(res, current_sum)
res = max(res, current_sum)
return res
Run Code Online (Sandbox Code Playgroud)
这是最大子数组问题的代码。我想要做的是找到长度最多为 K 的最大子数组。
示例:我们有一个数组 A = [3,-5 1 2,-1 4,-3 1,-2],我们想要找到长度最多为 K = …