In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The main content of this article is "detailed explanation of Python artificial intelligence mixed Gaussian model moving target detection", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "detailed understanding of Python artificial intelligence mixed Gaussian model moving target detection" bar!
Import cv2import numpy as np# algorithm extraction work Gaussian algorithm class gaussian: def _ _ init__ (self): self.mean = np.zeros ((1,3)) self.covariance = 0 self.weight = 0 Self.Next = None self.Previous = Noneclass Node: def _ _ init__ (self): self.pixel_s = None self.pixel_r = None self.no_of_components = 0 self.Next = Noneclass Node1: def _ init__ (self): self.gauss = None self.no_of_comp = 0 self.Next = Nonecovariance0 = 11.0def Create_gaussian (info1, info2 Info3): ptr = gaussian () if (ptr is not None): ptr.mean [1,1] = info1 ptr.mean [1,2] = info2 ptr.mean [1,3] = info3 ptr.covariance = covariance0 ptr.weight = 0.002 ptr.Next = None ptr.Previous = None return ptrdef Create_Node (info1, info2 Info3): N_ptr = Node () if (N_ptr is not None): N_ptr.Next = None N_ptr.no_of_components = 1 N_ptr.pixel_s = N_ptr.pixel_r = Create_gaussian (info1, info2) Info3) return N_ptrList_node = [] def Insert_End_Node (n): List_node.append (n) List_gaussian = [] def Insert_End_gaussian (n): List_gaussian.append (n) def Delete_gaussian (n): List_gaussian.remove (n) Class Process: def _ init__ (self, alpha, firstFrame): self.alpha = alpha self.background = firstFrame def get_value (self, frame): self.background = frame * self.alpha + self.background * (1-self.alpha) return cv2.absdiff (self.background.astype (np.uint8), frame) def denoise (frame): frame = cv2.medianBlur (frame, 5) frame = cv2.GaussianBlur (frame, (5,5) 0) return framecapture = cv2.VideoCapture ('1.mp4') ret, orig_frame = capture.read () if ret is True: value1 = Process (0.1, denoise (orig_frame)) run = Trueelse: run = Falsewhile (run): ret, frame = capture.read () value = False If ret is True: cv2.imshow ('input', denoise (frame)) grayscale = value1.get_value (denoise (frame)) ret, mask = cv2.threshold (grayscale, 15,255, cv2.THRESH_BINARY) cv2.imshow (' mask') Mask) key = cv2.waitKey (10) & 0xFF else: break if key = = 27: break if value = = True: orig_frame = cv2.resize (orig_frame, (340,260), interpolation=cv2.INTER_CUBIC) orig_frame = cv2.cvtColor (orig_frame Cv2.COLOR_BGR2GRAY) orig_image_row = len (orig_frame) orig_image_col = orig_frame [0] bin_frame = np.zeros ((orig_image_row, orig_image_col)) value = [] for i in range (0, orig_image_row): for j in range (0) Orig_image_col): N_ptr = Create_Node (orig_ framework [I] [0], orig_ framework [I] [1] Orig_ frame [I] [2]) if N_ptr is not None: N_ptr.pixel_s.weight = 1.0Insert_End_Node (N_ptr) else: print ("error") exit (0) nL = orig_image_row NC = orig_image_col dell = np.array ((1 3)) Mal_dist = 0; temp_cov = 0; alpha = 0.002; cT = 0.05; cf = 0.1; cfbar = 1.0-cf; alpha_bar = 1.0-alpha; prune =-alpha * cT; cthr = 0.00001; var = 0.0 muG = 0.0; muR = 0.0 MuB = 0; dR = 0; dB = 0; dG = 0; rval = 0; gval = 0; bval = 0; while (1): duration3 = 0; count = 0; count1 = 0; List_node1 = List_node Counter = 0; duration = cv2.getTickCount (); for i in range (0, nL): r_ptr = orig_ framework [I] b_ptr = bin_ framework [I] for j in range (0, nC): sum = 0.0; sum1 = 0.0 Close = False; background = 0; rval = r_ptr [0] [0]; gval = r_ptr [0] [0]; bval = r_ptr [0] [0]; start = List_ Node1 [counter] .pixel _ s Rear = List_ Node1 [counter] .pixel _ r; ptr = start; temp_ptr = None; if (List_ Node1 [counter] .no _ of_component > 4): Delete_gaussian (rear) List_ Node1 [counter] .no _ of_component = List_ Node1 [counter] .no _ of_component-1; for k in range (0, List_ Node1 [counter] .no _ of_component): weight = List_ Node1 [counter] .weight; mult = alpha / weight Weight = weight * alpha_bar + prune; if (close = = False): muR = ptr.mean [0]; muG = ptr.mean [1]; muB = ptr.mean [2]; dR = rval-muR DG = gval-muG; dB = bval-muB; var = ptr.covariance; mal_dist = (dR * dR + dG * dG + dB * dB); if ((sum
< cfbar) and (mal_dist < 16.0 * var * var)): background = 255; if (mal_dist < (9.0 * var * var)): weight = weight + alpha; if mult < 20.0 * alpha: mult = mult; else: mult = 20.0 * alpha; close = True; ptr.mean[0] = muR + mult * dR; ptr.mean[1] = muG + mult * dG; ptr.mean[2] = muB + mult * dB; temp_cov = var + mult * (mal_dist - var); if temp_cov < 5.0: ptr.covariance = 5.0 else: if (temp_cov >20): ptr.covariance = 20.0 else: ptr.covariance = temp_cov; temp_ptr = ptr If (weight <-prune): ptr = Delete_gaussian (ptr); weight = 0; List_ Node1 [counter] .no _ of_component = List_ node1 [counter] .no _ of_component-1 Else: sum + = weight; ptr.weight = weight; ptr = ptr.Next; if (close = = False): ptr = gaussian (); ptr.weight = alpha Ptr.mean [0] = rval; ptr.mean [1] = gval; ptr.mean [2] = bval; ptr.covariance = covariance0; ptr.Next = None; ptr.Previous = None Insert_End_gaussian (ptr); List_gaussian.append (ptr); temp_ptr = ptr; List_ Node1 [counter] .no _ of_components = List_ Node1 [counter] .no _ of_components + 1; ptr = start While (ptr! = None): ptr.weight = ptr.weight / sum; ptr = ptr.Next; while (temp_ptr! = None and temp_ptr.Previous! = None): if (temp_ptr.weight
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.