0

I'm trying write a code to find a nozzle spray angle (image) after binary process. I read something about hough transform to do this but I can't apply correctly. (Calculating the angle between two lines in an image in Python and How to find angle of hough lines detected?)

enter image description here

For a while I have this:

import cv2 
import numpy as np  
import math
import matplotlib.pyplot as plt

img_grey = cv2.imread('sprayang.jpg', cv2.IMREAD_GRAYSCALE)
img = cv2.GaussianBlur (img_grey, (5,5), 0)

th = 0
max_val = 255

    ret, o1 = cv2.threshold(img, th, max_val, cv2.THRESH_BINARY + cv2.THRESH_OTSU )

And the generated image is that: Btw I trying to fill this hole too

Using the angle measurement tool in ImageJ I measured about 90°.

1 Answers1

0
  1. cast 2 horizontal rays (from each direction)

  2. find first hit with your spray

    rays

    let call the 2D points p0,p1 from left and p2,p3

  3. compute angle

    smaller unsigned angle between 2 vectors in 2D is defined by dot product like this:

    ang = acos( dot( p1-p0 , p2-p1 ) / (|p1-p0|*|p2-p1|) )
    
                             (x1-x0)*(x2-x1) + (y1-y0)*(y2-y1)
    ang = acos( ------------------------------------------------------------- )
                sqrt( (x1-x0)^2 + (y1-y0)^2 ) * sqrt( (x2-x1)^2 + (y2-y1)^2 )
    
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • I will try start with this, Spektre. But, sincererly I didn't understand very well. Is this horizontal ray specific? Like, if I change the image, will I change that value too? – Vinicius Carreira Nov 19 '20 at 23:24
  • @ViniciusCarreira no you do not need to change image (unless you want to for debug) just select some `y` then `for` loop through `x` from 0 to Width (or vice versa for the opposite direction) , read pixel(x,y) value and if not background stop and remember the last x ... the y values select so that one is near start of the spray cone and one near bottom ... either manualy by mouse or hard-code or from BBOX ... – Spektre Nov 20 '20 at 07:31