1

I want to detect joints in a sugarcane stick and do not want the border lines to be detected this is my original Original Image, and after applying Morphological Gradient I got this output image. The desired output that I need is to detect only vertical edges that is the joints, the desired output are only the red lines in this image.

So, it would be great if anyone could help me out!

2
  • 2
    Have you already tried to get contours or detect lines in your image? It's always good to share some code so others can better see were you got stuck. Commented May 11, 2022 at 14:35
  • Yes, I did try to get contours or detect lines in the image but they don't show expected results Commented May 18, 2022 at 16:53

2 Answers 2

2

You can try to enhance the following code to find vertical edges as you need

img = cv2.imread("edges.png")
mask = img[:,:,0]

height, width = mask.shape

mask = cv2.threshold(mask, 100, 255, cv2.THRESH_BINARY)[1]
#cv2.imshow("mask", mask)

vertical_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, height//30))
vertical_lines = cv2.erode(mask, vertical_kernel, iterations=1)
vertical_lines = cv2.dilate(vertical_lines, vertical_kernel, iterations=1)

#cv2.imshow("vertical_lines", vertical_lines)

img[vertical_lines > 0, 2] = 255
cv2.imshow("img", img)
cv2.waitKey(0)

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Which of the image have you taken in as input to get this image, because I am trying the same with gray image but I am unable to get the results
0

SUGARCAN BUD DETECTION & CUTTING MECHANISM

Finally I got the right and working answer for my question, It detects the buds using HOG Circle Transform and shows red circle around it.

It also passes a serial info to the COM4 port of the computer so that the cutter can be operated at the right time.

The program is used to Identify, Detect And Cut a sugarcane bud without human interference

Here's a link to my research paper - https://www.irjet.net/archives/V10/i6/IRJET-V10I627.pdf

import cv2
import numpy as np
import serial
import time
import threading

ser = serial.Serial('COM4',bytesize=8, baudrate=9600, timeout=1)  # Replace 'COM3' with the appropriate serial port
time.sleep(3)

cap = cv2.VideoCapture(0)
circle_detected = False

flag = False

def callback():
    global flag
    flag = True

while True:
    # Capture frame-by-frame
    ret, frame = cap.read()

# Convert frame to grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Apply Gaussian blur to remove noise
blur = cv2.GaussianBlur(gray, (5, 5), 0)

# Detect circles using Hough Circle Transform
circles = cv2.HoughCircles(blur, cv2.HOUGH_GRADIENT, 1, 20,
                           param1=60, param2=34, minRadius=10, maxRadius=50)

# Draw circles around detected centers and set flag if circle is detected
if circles is not None:
    circle_detected = True
    circles = np.round(circles[0, :]).astype("int")
    for (x, y, r) in circles:
        cv2.circle(frame, (x, y), r, (0, 0, 255), 2)

if circle_detected:
    if threading.active_count() <= 1:
        timer = threading.Timer(7.0, callback)
        timer.start()
    if circle_detected and flag:
        flag = False
        ser.write(b'00000001')
        print("Sent data to serial port")
    circle_detected = False


# Display the resulting frame
cv2.imshow('Sugarcane Buds Detection', frame)

# Exit program when 'q' is pressed
if cv2.waitKey(1) == ord('q'):
    break

# Release the capture
cap.release()
cv2.destroyAllWindows()

# Flag signal if circle is detected
if circle_detected:
    print("Circle detected!")
else:
    print("No circle detected.")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.