0

I am trying to implement face detection tutorial of openCV but my google colab kernel is crashed when following code is used:

from google.colab import files
xml = files.upload()

import numpy as np
import cv2 as cv
face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv.CascadeClassifier('haarcascade_eye.xml')
img = cv.imread('elonMusk.jpg')
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
    cv.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    roi_gray = gray[y:y+h, x:x+w]
    roi_color = img[y:y+h, x:x+w]
    eyes = eye_cascade.detectMultiScale(roi_gray)
    for (ex,ey,ew,eh) in eyes:
        cv.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
cv.imshow('img',img)
cv.waitKey(0)
cv.destroyAllWindows()

Error displayed : Runtmie died. Automatically restarting. All the desired xml and jpg files were uploaded.

The code used is exactly the same code as used for face detection openCV tutorial. https://docs.opencv.org/3.4/d7/d8b/tutorial_py_face_detection.html

Mel
  • 5,837
  • 10
  • 37
  • 42
Vinay Sharma
  • 319
  • 1
  • 5
  • 13
  • 1
    `cv.imshow('img',img)` is not meant to work on colab, it is just for debugging purposes on local machine, to debug your images, you can use `matplotlib.show` I guess – ZdaR Dec 19 '18 at 06:27
  • @ZdaR , Thanks !! Its working fine with matplotlib. – Vinay Sharma Dec 19 '18 at 06:57

1 Answers1

0

Google Colab is actually not designed to run opencv smoothly, so you will absolutely get an error. You should use Jupiter notebook or any other IDE.