鱼C论坛

 找回密码
 立即注册
查看: 772|回复: 1

[已解决]opencv显示图片问题

[复制链接]
发表于 2023-6-1 12:50:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import requests, cv2
  2. import fake_useragent as fakeua
  3. import numpy as np
  4. from bs4 import BeautifulSoup
  5. from io import BytesIO

  6. url = "https://xxxxx.com.cn"
  7. ua = fakeua.FakeUserAgent()
  8. headers = {
  9.     "User-Agent": ua.googlechrome
  10. }
  11. response = requests.get(url, headers=headers)
  12. soup = BeautifulSoup(response.content.decode(response.encoding), 'lxml')
  13. imgs = soup.select('.fl_icn_g')
  14. for img in imgs:
  15.     url2 = img.a.img['src']
  16.     image = requests.get("https://xxxxx.com.cn/" + url2, headers=headers)
  17.     image = np.array(bytearray(image.content), dtype=np.uint8)
  18.     image = cv2.imdecode(image, cv2.IMREAD_COLOR)
  19.     cv2.namedWindow('wt', cv2.WINDOW_NORMAL)
  20.     cv2.imshow('My1919810', img)
  21.     cv2.waitkey()
  22.     break
复制代码
  1. >>>
  2. ===================== RESTART: C:\Users\ASUS\Desktop\111.py ====================
  3. Traceback (most recent call last):
  4.   File "C:\Users\ASUS\Desktop\111.py", line 20, in <module>
  5.     cv2.namedWindow('wt', cv2.WINDOW_NORMAL)
  6. cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:1255: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvNamedWindow'
复制代码

是opencv不支持win11吗,gpt说opencv的官方文档提到opencv支持windwos10
最佳答案
2023-6-1 13:56:44
代码中使用的窗口名称和等待用户按键的时间有误,请将 cv2.imshow('My1919810', img) 改为 cv2.imshow('wt', image),并将 cv2.waitkey() 改为 cv2.waitKey(0)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-6-1 13:56:44 From FishC Mobile | 显示全部楼层    本楼为最佳答案   
代码中使用的窗口名称和等待用户按键的时间有误,请将 cv2.imshow('My1919810', img) 改为 cv2.imshow('wt', image),并将 cv2.waitkey() 改为 cv2.waitKey(0)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-20 14:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表