最近在研究通过golang调用摄像头,按照 https://gocv.io/ 介绍进行安装,期间各种问题。。。
包括但不限于:
aomedia.googlesource.com
, gist.githubusercontent.com
, raw.githubusercontent.com
等网站
解决方法:
1、查询网站IP 获取其IP地址,然后修改系统 hosts
文件
2、直接全局代理。
macOS下修改
~/.bash_profile
,增加:
# 代理地址根据自己情况修改
alias proxy='export all_proxy=socks5://127.0.0.1:50237'
alias unproxy='unset all_proxy'
运行
brew install opencv
前,先proxy
一下
我的苹果本是 Sierra
系统,好不容易一步步下载完成要进行安装了,结果提示不支持 Sierra
,还友情提示不要去提问为什么......不支持你早说啊,等什么都准备好了才说……
么得办法,先升级系统到 Catalina
。。。
升级之后,重新开始下载(两个系统对应的包不一样)。
漫长的等待之后,安装时提示 xcode
过老……那就升级 xcode
吧,可是 AppStore 总是提示系统空间不足,无法安装。。。只能忍痛删掉好多东西。。。差不多空出 40G
的时候,终于可以安装了。
安装 xcode
之后,重新执行安装命令,可算是成功了。
运行示例里的 capwindow
,终于能看到画面了。可是有几个示例总是运行不起来,提示:
```
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(4.4.0) /tmp/opencv-20200909-20320-7icpjn/opencv-4.4.0/modules/dnn/src/dnn.cpp:321: error: (-215:Assertion f
// 冒泡排序
func bubbleSort(nums []int) {
size := len(nums)
for i := 0; i < size - 1; i++ {
for j := i + 1; j < size; j++ {
if nums[j] < nums[i] {
nums[i], nums[j] = nums[j], nums[i]
}
}
}
}
// 选择排序
func selectSort(nums []int) {
size := len(nums)
idx := 0
for i := 0; i < size - 1; i++ {
idx = i
for j := i + 1; j < size; j++ {
if nums[j] < nums[idx] {
idx = j
}
}
if idx != i {
nums[i], nums[idx] = nums[idx], nums[i]
}
}
}
// 快速排序
func quickSort(nums []int, left, right int) {
tmp := nums[left]
i, j := left, right
for i < j {
for i < j && nums[j] >= tmp {
j--
}
nums[i] = nums[j]
for i < j && nums[i] <= tmp {
i++
}
nums[j] = nums[i]
}
nums[i] = tmp
if i > left + 1 {
quickSort(nums, left, i - 1)
}
按照官方文档进行操作,执行 npm start
时提示不明白 start
是什么操作,在package.json内添加 start
定义:
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
});
preload.js
文件内容:
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}`, process.versions[type])
}
})
index.html
文件增加标签id:
We are using node <span id="node"></span>,
Chrome <span id="chrome"></span>,
and Electron <span id="electron"></span>.
再次执行,显示成功。
//二分查找,data为由小到大排序的数组,target为要找的目标值
func BinarySearch(data []int, target int) int {
min := 0
max := len(data)
for min <= max {
cur := (min + max) / 2
println(min, cur, max, target, data[cur])
if target == data[cur] {
return cur
} else if target < data[cur] {
max = cur - 1
} else {
min = cur + 1
}
}
return -1
}