Skip to content

Commit 4f90725

Browse files
opencv image example
1 parent 0803946 commit 4f90725

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

examples/textures/opencv.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import cv2 as cv
2+
from pyray import *
3+
4+
opencv_image = cv.imread("resources/raylib_logo.jpg")
5+
if opencv_image is None:
6+
exit("Could not read the image.")
7+
8+
screenWidth = 800
9+
screenHeight = 450
10+
init_window(screenWidth, screenHeight, "example - image loading")
11+
12+
pointer_to_image_data = ffi.from_buffer(opencv_image.data)
13+
raylib_image = Image(pointer_to_image_data, 256, 256, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8)
14+
texture = load_texture_from_image(raylib_image)
15+
unload_image(raylib_image)
16+
17+
while not window_should_close():
18+
begin_drawing()
19+
clear_background(RAYWHITE)
20+
draw_texture(texture, int(screenWidth/2 - texture.width/2), int(screenHeight/2 - texture.height/2), WHITE)
21+
end_drawing()
22+
23+
unload_texture(texture)
24+
close_window()
25+
26+

0 commit comments

Comments
 (0)