Guest User

Untitled

a guest
Sep 19th, 2025
14,585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. def onCook(scriptOp):
  5.  
  6. params = op('areaParams')
  7. MIN_AREA = int(params['min'])
  8. MAX_AREA = int(params['max'])
  9.  
  10. src = scriptOp.inputs[0].numpyArray(delayed=False)
  11. src8 = (src * 255).astype('uint8')
  12. gray = src8[..., 0]
  13.  
  14. contours, _ = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
  15.  
  16. w_img = op('video').width
  17. h_img = op('video').height
  18.  
  19. dat = op('blobData')
  20. dat.clear()
  21. dat.appendRow(["id", "u", "v", "width", "height"])
  22.  
  23. idx = 0
  24. for cnt in contours:
  25. area = cv2.contourArea(cnt)
  26. if area < MIN_AREA or area > MAX_AREA:
  27. continue
  28.  
  29. x, y, w, h = cv2.boundingRect(cnt)
  30.  
  31. cx = (x + w / 2) / w_img
  32. cy = (y + h / 2) / h_img
  33.  
  34. sx = w / w_img
  35. sy = h / h_img
  36.  
  37. dat.appendRow([str(idx), str(cx), str(cy), str(sx), str(sy)])
  38. idx += 1
  39.  
  40. return
  41.  
Advertisement
Add Comment
Please, Sign In to add comment