Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52a45b2

Browse files
committed
在Django里展示图片
1 parent5568035 commit52a45b2

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

‎my09-图片展示/NOTE.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
- 参考
4+
-[Creating a face detection API with Python and OpenCV (in just 5 minutes)](https://www.pyimagesearch.com/2015/05/11/creating-a-face-detection-api-with-python-and-opencv-in-just-5-minutes/)
5+
-[How to stream opencv frame with django frame in realtime?](https://stackoverflow.com/questions/45906482/how-to-stream-opencv-frame-with-django-frame-in-realtime)

‎my09-图片展示/cv_html.png‎

85.3 KB
Loading
29.5 KB
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
##在Django里展示图片
2+
3+
- 定义路径
4+
```python
5+
from django.conf.urlsimport url
6+
7+
from .viewsimport cvtest
8+
9+
10+
urlpatterns= {
11+
url(r'^display_image$', cvtest.display_image,name='display_image'),
12+
13+
}
14+
15+
```
16+
17+
- 编写视图
18+
```python
19+
from django.httpimport HttpResponse
20+
import cv2
21+
22+
23+
defdisplay_image(request):
24+
fn='/Users/play/Desktop/114311.jpg'
25+
img= cv2.imread(fn)
26+
img[:, :,2]=0# 对图片进行处理
27+
ret, jpeg= cv2.imencode('.jpg', img)
28+
return HttpResponse(jpeg.tostring(),content_type="multipart/x-mixed-replace")
29+
30+
```
31+
- 在浏览器里访问
32+
-http://0.0.0.0:8000/test/display_image
33+
-![display_image](display_image.jpg"display_image")
34+
35+
- 在网页里引用
36+
-![display_image](cv_html.png"display_image")
37+
```html
38+
<imgsrc='/test/display_image'></img>
39+
```
40+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp