發表文章

目前顯示的是有「macos」標籤的文章

[ OpenCV ] MacOS 無法使用 cv2.imshow()播放 Webcam的替代方案

圖片
OpenCV在 MacOS系統下有些功能無法使用, Python官方 也清楚地告知了。 IMPORTANT NOTE MacOS and Linux wheels have currently some limitations: video related functionality is not supported (not compiled with FFmpeg) for example  cv2.imshow()  will not work (not compiled with GTK+ 2.x or Carbon support) 嘗試了各種 OpenCV的安裝方法,OpenCV在 MacOS上總會碰上不少挫折。據說有人跟著這篇 安裝指南 後,能正常運作。但我安裝到一半仍然卡關了。 但為了使用 Webcam,不得不做一些妥協。若不願意在別的系統上開發,就只好先用一些替代方案。 import cv2 import numpy as np import matplotlib.pyplot as plt face_cascade = cv2.CascadeClassifier('./cascades/haarcascade_frontalface_default.xml') cam = cv2.VideoCapture(0) plt.ion() while(True): ret, img = cam.read() gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.2, 3) for (x,y,w,h) in faces: img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) img = cv2.flip(img,1) # 1 水平翻轉, 0 垂直翻轉, -1 水平垂直翻轉 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) plt.imshow(img) plt.pause(.01) plt.cla() ...

[ Jupyter Nootbook ] 開啟時出現錯誤 ( MacOS 10.12.5 )

開啟 Jupyter Notebook 時出現以下錯誤訊息 0:97: execution error: "http://localhost:8888/tree?token=***" doesn’t understand the “open location” message. (-1708) 雖然直接複製終端機提供的網址,一樣可以正常運作,但心裡總是有點疙瘩。 解決方法如下: 終端機輸入: $ open ~/.bash_profile # or $ touch ~/.bash_profile; open ~/.bash_profile  # 若找不到文件的話 把以下代碼貼入文件中: BROWSER=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome export BROWSER 我的狀況這樣就解決了,感謝 @andrewjmacrae 在 GitHub  指點迷津。 其他瀏覽器的使用者可能要再多嘗試一下了。