利用opencv进行图像处理过程中出现报错TypeError: img is not a numpy array, neither a scalar
opencv
OpenCV: 开源计算机视觉库
项目地址:https://gitcode.com/gh_mirrors/opencv31/opencv
·

在图形处理过程中出现上面的错误,如果你也有相同问题那么可以用以下方法来解决。
报错原因:cv2只能处理BGR格式图片,而image.open()读取的图片是RBG格式。
解决方式:把RBG图片转化成BGR格式,转化代码如下所示:
#将RGB转换成BGR方法
r,g,b = cv2.split(median)
out = cv2.merge([b,g,r])
把上述代码插入到你的图片处理完毕的后面对准备输出图片进行转换就可以了。
OpenCV: 开源计算机视觉库
最近提交(Master分支:4 个月前 )
1f47f5ba
imgproc: replace assertion in cornerSubPix with descriptive error #28404
Replace CV_Assert with explicit bounds check for initial corners in cornerSubPix.
This provides a descriptive runtime error instead of abrupt termination,
improving error handling for Python and C++ users.
No algorithmic or behavioral change for valid inputs.
Fixes #25139 (Related to #7276).
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
15 小时前
fba658b9
Improve precision of RotatedRect::points 1 天前
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)