For some reason I can’t get this code to run without seg faulting, it worked fine on my raspi, i just changed the video source over to the nvargus and it was seg faulting. I started re-wrote the function line by line, running the code after each line to see where the failure is induced.
The first part of the code is fine up until i write snapshot, but once I add “circles =cv2.HoughCircles” is where i get it to seg fault. Any idea what’s going on?
Also how do you suppress the output produced by GST_ARGUS?
CODE
import cv2
import configparser
import os
import numpy as np
snapshot='/tmp/snapshot.jpg'
snapshot_circle='/tmp/snapshot2.jpg'
width=1920
height=1080
fps=60
crop_y=80
crop_h=1000
crop_x=580
crop_w=1000
dev = 'nvarguscamerasrc ! video/x-raw(memory:NVMM), width=%d, height=%d, format=(string)NV12, framerate=(fraction)%d/1 !nvvidconv flip-method=%d ! nvvidconv ! video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! videoconvert ! appsink' % (width, height, fps, 0, width, height)
cap = cv2.VideoCapture(dev, cv2.CAP_GSTREAMER)
ret_val, img = cap.read()
img = img[crop_y:crop_y+crop_h,crop_x:crop_x+crop_h]
cv2.imwrite(snapshot, img)
color=img.copy()
gray = cv2.cvtColor(color, cv2.COLOR_BGR2GRAY)
gray = cv2.medianBlur(gray, 5)
low=30
high=100
rows= gray.shape[0]
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, rows/1, param1=100, param2=30, minRadius=225, maxRadius=250)
if circles is not None:
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
center = (i[0], i[1])
radius = i[2]
cv2.circle(color, center, radius, (255, 255, 255), -1)
cv2.imwrite(snapshot_circle, color)
cap.release()
OUTPUT
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 4032 x 3040 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 22.250000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1920 x 1080 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 22.250000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 2592 x 1944 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 22.250000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 2560 x 1440 FR = 40.000000 fps Duration = 25000000 ; Analog Gain range min 1.000000, max 22.250000; Exposure Range min 13000, max 683709000;
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 1
Output Stream W = 1920 H = 1080
seconds to Run = 0
Frame Rate = 59.999999
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
[ WARN:0] global /home/test/opencv/modules/videoio/src/cap_gstreamer.cpp (1081) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
GST_ARGUS: Cleaning up
Segmentation fault (core dumped)