Gtk-WARNING **: cannot open display: :1 openCV Navio2

Hello there,
I’m trying to run openCV code on Navio2 and Raspberry pi but I get an error like this:

image

My code is like this:

import cv2
from imutils.video import VideoStream
import imutils
import time

 #kullanacağımız data dosyası
cascade = cv2.CascadeClassifier("cascade.xml")

vs = VideoStream(usePiCamera=True).start() #Pi Cam başlatma
time.sleep(2.0)

while True:
    frame = vs.read()
    frame = imutils.resize(frame, width=500) #500x500 lük bir izleme ekranı

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#görüntüyü net işleyebilmek için şablona gri filtre uyguladık

    faces = cascade.detectMultiScale(gray,1.3,3)
#.detectMultiSclae(şablon,ölçek,hassasiyet)
    for x,y,w,h in faces :
        cv2.rectangle(frame,(x,y),(x+w,y+h),(20,200,100),2)
#cv2.rectangle(şablon, yüz koordinatları , çerçeve koordinatları,BGR cinsinden rengi,çerçeve kalınlığı)

    cv2.imshow("Bitki Tespit Sistemi",frame)
#cv2.imshow(pencere ismi,şablon)

#eğer şablonları gray seçerseniz önizlemeyi siyah-beyaz görebilirsiniz.

    p= cv2.waitKey(1)

    if p== ord("q"): #q ya basılırsa pencereyi kapat kodu durdur.
        break


cv2.destroyAllWindows()
vs.stop()

Hi Ramazan,

As I know, this issue might appear if you’re using a headless Raspberry PI, meaning that you have no connected display. This means that Raspberry can’t show anything. To show the info on the computer you’re connecting from, you need to set your display to the IP of that computer.

However, please note that we haven’t run the OpenCV code on Navio2. I can’t be of much help with it. That’s why I’d suggest checking out the OpenCV-dedicated forums on this issue, like this one.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.