-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xinyuli1204
committed
Dec 8, 2023
1 parent
6e0b038
commit 7238f78
Showing
6 changed files
with
183 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# https://github.com/fixstars/ion-csharp/blob/master/test/Test.cs | ||
from ionpy import Node, Builder, Buffer, PortMap, Port, Param, Type, TypeCode | ||
import numpy as np | ||
import cv2 | ||
import os | ||
|
||
|
||
def test_portmap_access(): | ||
|
||
w = 200 | ||
h = 200 | ||
t = Type(code_=TypeCode.Uint, bits_=8, lanes_=1) | ||
width = Param(key='width', val=str(w)) | ||
height = Param(key='height', val=str(h)) | ||
urls = Param(key="urls",val="http://optipng.sourceforge.net/pngtech/img/lena.png;http://upload.wikimedia.org/wikipedia/commons/0/05/Cat.png") | ||
|
||
builder = Builder() | ||
builder.set_target(target='host') | ||
# make sure path includes libion-bb.so | ||
builder.with_bb_module(path='/home/xinyu.li/dependency/ion-kit-install/lib/libion-bb.so') | ||
|
||
node = builder.add('image_io_cameraN').set_param(params=[width, height, urls]) | ||
|
||
|
||
|
||
sizes = (w, h, 3) | ||
obuf1 = Buffer(type=t, sizes=sizes) | ||
obuf2 = Buffer(type=t, sizes=sizes) | ||
odata_bytes1 = np.zeros(w*h*3,dtype=np.uint8).tobytes() | ||
odata_bytes2 = np.zeros(w*h*3,dtype=np.uint8).tobytes() | ||
obuf1.write(data=odata_bytes1) | ||
obuf2.write(data=odata_bytes2) | ||
|
||
port_map = PortMap() | ||
port_map.set_buffer(port=node.get_port(key='output')[0], buffer=obuf1) | ||
port_map.set_buffer(port=node.get_port(key='output')[1], buffer=obuf2) | ||
|
||
builder.run(port_map=port_map) | ||
|
||
out_byte_arr1 = obuf1.read(len(odata_bytes1)) | ||
out_byte_arr2 = obuf2.read(len(odata_bytes2)) | ||
|
||
img_out1 = np.frombuffer(out_byte_arr1, dtype=np.uint8) | ||
img_out2 = np.frombuffer(out_byte_arr2, dtype=np.uint8) | ||
|
||
|
||
b1 = img_out1[:w*h] | ||
g1 = img_out1[w*h:2*w*h] | ||
r1 = img_out1[2*w*h:] | ||
|
||
b2 = img_out2[:w*h] | ||
g2 = img_out2[w*h:2*w*h] | ||
r2 = img_out2[2*w*h:] | ||
# | ||
img_out1 = cv2.merge((r1,g1,b1)).reshape(w,h,3) | ||
img_out2 = cv2.merge((r2,g2,b2)).reshape(w,h,3) | ||
|
||
DISPLAY = os.getenv("DISPLAY","false").lower()=="true" | ||
|
||
if DISPLAY: | ||
cv2.imshow("display1", img_out1) | ||
cv2.imshow("display2", img_out2) | ||
cv2.waitKey(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include <iostream> | ||
#include <ion/ion.h> | ||
|
||
// to display | ||
#include <opencv2/core.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
#include <opencv2/highgui.hpp> | ||
#define DISPLAY | ||
|
||
using namespace ion; | ||
|
||
void display_image_uint8(Halide::Buffer<uint8_t> buffer, std::string filename) { | ||
int width = buffer.width(); | ||
int height = buffer.height(); | ||
int channels = buffer.channels(); | ||
cv::Mat img_out; | ||
if (channels == 3) { | ||
cv::merge(std::vector<cv::Mat>{ | ||
cv::Mat(height, width, CV_8U, buffer.data() + width * height * 2), //b | ||
cv::Mat(height, width, CV_8U, buffer.data() + width * height * 1), //g | ||
cv::Mat(height, width, CV_8U, buffer.data())}, //r | ||
img_out); | ||
|
||
} else { | ||
cv::Mat img_out(height, width, CV_8U, buffer.data()); | ||
} | ||
#ifdef DISPLAY | ||
cv::imshow( "Display window: " + filename, img_out); | ||
cv::waitKey(3000); | ||
#endif | ||
} | ||
|
||
|
||
int main(int argc, char *argv[]) { | ||
try { | ||
// TODO: Test with FullHD | ||
const int width = 200; | ||
const int height = 150; | ||
|
||
Param wparam("width", std::to_string(width)); | ||
Param hparam("height", std::to_string(height)); | ||
|
||
Port wport("width", Halide::type_of<int32_t>()); | ||
Port hport("height", Halide::type_of<int32_t>()); | ||
|
||
Builder b; | ||
b.set_target(Halide::get_target_from_environment()); | ||
b.with_bb_module("ion-bb"); | ||
|
||
Node n; | ||
n = b.add("image_io_cameraN").set_param( | ||
wparam, | ||
hparam, | ||
Param{"num_devices", "2"}, | ||
Param{"urls", "http://optipng.sourceforge.net/pngtech/img/lena.png;http://upload.wikimedia.org/wikipedia/commons/0/05/Cat.png"} | ||
//input urls split by ';' | ||
); | ||
|
||
|
||
PortMap pm; | ||
Halide::Buffer<uint8_t> out_buf0( width, height,3); | ||
Halide::Buffer<uint8_t> out_buf1( width, height,3); | ||
|
||
|
||
|
||
|
||
|
||
pm.set(wport, width); | ||
pm.set(hport, height); | ||
|
||
pm.set(n["output"][0],out_buf0); | ||
pm.set(n["output"][1],out_buf1); | ||
|
||
b.run(pm); | ||
display_image_uint8(out_buf0, "display.png"); | ||
display_image_uint8(out_buf1, "display.png"); | ||
std::cout << "Success" << std::endl; | ||
} catch (const std::exception &e) { | ||
std::cerr << e.what() << std::endl; | ||
return -1; | ||
} catch (...) { | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} |