forked from pjreddie/vision-hw0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uwimg.py
70 lines (49 loc) · 1.6 KB
/
uwimg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sys, os
from ctypes import *
import math
import random
def c_array(ctype, values):
arr = (ctype*len(values))()
arr[:] = values
return arr
class IMAGE(Structure):
_fields_ = [("w", c_int),
("h", c_int),
("c", c_int),
("data", POINTER(c_float))]
#lib = CDLL("/home/pjreddie/documents/455/libuwimg.so", RTLD_GLOBAL)
#lib = CDLL("libuwimg.so", RTLD_GLOBAL)
lib = CDLL(os.path.join(os.path.dirname(__file__), "libuwimg.so"), RTLD_GLOBAL)
make_image = lib.make_image
make_image.argtypes = [c_int, c_int, c_int]
make_image.restype = IMAGE
free_image = lib.free_image
free_image.argtypes = [IMAGE]
get_pixel = lib.get_pixel
get_pixel.argtypes = [IMAGE, c_int, c_int, c_int]
get_pixel.restype = c_float
set_pixel = lib.set_pixel
set_pixel.argtypes = [IMAGE, c_int, c_int, c_int, c_float]
rgb_to_grayscale = lib.rgb_to_grayscale
rgb_to_grayscale.argtypes = [IMAGE]
rgb_to_grayscale.restype = IMAGE
rgb_to_hsv = lib.rgb_to_hsv
rgb_to_hsv.argtypes = [IMAGE]
hsv_to_rgb = lib.hsv_to_rgb
hsv_to_rgb.argtypes = [IMAGE]
shift_image = lib.shift_image
shift_image.argtypes = [IMAGE, c_int, c_float]
clamp_image = lib.clamp_image
clamp_image.argtypes = [IMAGE]
load_image_lib = lib.load_image
load_image_lib.argtypes = [c_char_p]
load_image_lib.restype = IMAGE
def load_image(f):
return load_image_lib(f.encode('ascii'))
save_image_lib = lib.save_image
save_image_lib.argtypes = [IMAGE, c_char_p]
def save_image(im, f):
return save_image_lib(im, f.encode('ascii'))
if __name__ == "__main__":
im = load_image("data/dog.jpg")
save_image(im, "hey")