Mac安装opencv 出错 No available formula with the name “opencv“.

本文讲述了用户在Mac上使用brew安装OpenCV时遭遇的错误,包括搜索无果和Tapping homebrew/core后成功安装的过程。通过删除库并更新,解决了找不到类似名称的Formula问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

详细出错信息:

xideMacBook-Pro:~ xi$ brew install opencv
Warning: No available formula with the name "opencv".
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

解决方法:

xideMacBook-Pro:~ xi$ rm -rf /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
xideMacBook-Pro:~ xi$ brew update

然后再执行安装命令:

xideMacBook-Pro:~ xi$ brew install opencv
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 1269148, done.
remote: Counting objects: 100% (140/140), done.
remote: Compressing objects: 100% (66/66), done.
remote: Total 1269148 (delta 82), reused 127 (delta 74), pack-reused 1269008
Receiving objects: 100% (1269148/1269148), 512.88 MiB | 2.72 MiB/s, done.
Resolving deltas: 100% (875122/875122), done.
Tapped 3 commands and 6283 formulae (6,626 files, 561.8MB).
==> Downloading https://ghcr.io/v2/homebrew/core/eigen/manifests/3.4.0_1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/eigen/blobs/sha256:211fd7f1d58b383e3d64335c08a376a7d8433007ce61410ead032
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:211fd7f1d58b383e3d64335c08a376a7d843
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/gflags/manifests/2.2.2-1
......

完美解决。

### Python 手写数学公式识别的代码实现 以下是基于YOLOv10的手写数学公式识别系统的Python代码框架,涵盖了模型加载、预测以及LaTeX格式转换的核心部分: #### 加载依赖库 首先需要安装必要的依赖项,包括 `torch` 和 `opencv-python`。 ```bash pip install torch torchvision opencv-python matplotlib ``` #### 主程序代码 以下是一个简单的代码示例,展示如何使用预训练的YOLOv10模型来完成手写数学公式的检测与识别任务。 ```python import cv2 import torch from PIL import Image from yolov10.models.experimental import attempt_load from yolov10.utils.general import non_max_suppression, scale_coords from yolov10.utils.plots import Annotator def load_model(weights_path='yolov10.pt'): """ Load the pre-trained YOLOv10 model. """ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model = attempt_load(weights_path, map_location=device) # 自动加载权重文件 return model, device def predict_image(model, image_path, img_size=640, conf_thres=0.5, iou_thres=0.45): """ Perform prediction on a single input image using the loaded YOLOv10 model. Parameters: model (torch.nn.Module): The loaded YOLOv10 model. image_path (str): Path to the input image file. img_size (int): Input size for the model. conf_thres (float): Confidence threshold for filtering detections. iou_thres (float): IoU threshold for NMS. Returns: list: List of detected symbols and their bounding boxes. """ device = next(model.parameters()).device img = cv2.imread(image_path) img_resized = letterbox(img, new_shape=img_size)[0] img_tensor = transform_image(img_resized).to(device) pred = model(img_tensor)[0] det = non_max_suppression(pred, conf_thres, iou_thres)[0] annotator = Annotator(Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))) results = [] if det is not None and len(det): det[:, :4] = scale_coords(img_tensor.shape[2:], det[:, :4], img.shape).round() for *xyxy, conf, cls in reversed(det): label = f'{model.names[int(cls)]} {conf:.2f}' annotator.box_label(xyxy, label, color=(0, 255, 0)) results.append({ 'symbol': model.names[int(cls)], 'bbox': [int(x) for x in xyxy], 'confidence': float(conf), }) annotated_img = annotator.result() annotated_img.save("annotated_result.png") # Save result as an image return results def transform_image(img): """ Transform the input image into tensor format suitable for the model. """ img = img.transpose((2, 0, 1))[::-1] # HWC to CHW, BGR to RGB img = np.ascontiguousarray(img) img = torch.from_numpy(img).float().div(255.0).unsqueeze(0) return img def letterbox(im, new_shape=(640, 640), color=(114, 114, 114)): """ Resize and pad images while maintaining aspect ratio. """ shape = im.shape[:2] # current shape [height, width] r = min(new_shape[0] / shape[0], new_shape[1] / shape[1]) new_unpad = int(round(shape[1] * r)), int(round(shape[0] * r)) dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1] # wh padding dw /= 2 # divide padding into 2 sides dh /= 2 if shape[::-1] != new_unpad: # resize im = cv2.resize(im, new_unpad, interpolation=cv2.INTER_LINEAR) top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1)) left, right = int(round(dw - 0.1)), int(round(dw + 0.1)) im = cv2.copyMakeBorder(im, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color) # add border return im, (dw, dh) if __name__ == "__main__": weights_path = "path_to_your_weights/yolov10.pt" image_path = "example_formula.jpg" model, _ = load_model(weights_path) predictions = predict_image(model, image_path) latex_output = "" for symbol_info in predictions: latex_output += symbol_info['symbol'] + " " with open("output.tex", "w") as tex_file: tex_file.write(latex_output.strip()) # 将结果保存为LaTeX格式文件 print(f"Recognition completed! Results saved as LaTeX output.") ``` 此代码实现了以下几个功能: - **模型加载**:通过 `attempt_load` 函数加载预训练好的YOLOv10模型[^1]。 - **图像预处理**:调整输入图像大小并保持宽高比例不变,填充空白区域以适配模型需求[^1]。 - **目标检测**:调用 `non_max_suppression` 对检测框进行非极大值抑制操作,过滤冗余检测结果[^1]。 - **可视化标注**:利用 `Annotator` 类绘制边界框及其对应的标签信息[^1]。 - **LaTeX 输出**:将检测到的符号序列化为字符串形式,并存储至 `.tex` 文件中以便进一步编辑和排版[^1]。 ### 注意事项 - 需要下载官方发布的 YOLOv10 权重文件或者自行训练适合特定场景的数据集上的模型[^1]。 - 数据增强策略对于提升复杂背景下的识别精度至关重要,在实际应用前建议针对具体任务微调超参数设置[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千笺客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值