예제 #1
0
def main():
    # Command line options:
    parser = ArgumentParser(description="A very simple VisionCpp demo. Loads "
                            "an image from file, performs some colour space "
                            "conversions, and displays the result.")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        help="verbose output printing")
    parser.add_argument("-C",
                        "--computecpp",
                        type=str,
                        metavar="PATH",
                        default="~/ComputeCpp-CE-0.1-Linux",
                        help="Path to ComputeCpp installation directory")
    args = parser.parse_args()
    if args.verbose: logging.basicConfig(level=logging.DEBUG)
    vp.init(args.computecpp)

    image_path = os.path.join(os.path.dirname(__file__), "lena.jpg")

    # VisionCpp expression tree:
    image_in = vp.Image(image_path)
    node1 = vp.BGRToRGB(image_in)
    node2 = vp.U8C3ToF32C3(node1)
    node3 = vp.RGBToHSV(node2)
    node4 = vp.HSVToRGB(node3)
    node5 = vp.F32C3ToU8C3(node4)
    node6 = vp.RGBToBGR(node5)
    output = vp.show(node6)

    vp.run(output)
예제 #2
0
    def test_load_and_show_gpu(self):
        node_in = vp.Image("examples/lena.jpg")
        node_out = vp.show(node_in)
        self.assertEqual(codegen.generate(node_out, "gpu",
                                          use_clang_format=False)[1],
"""\
#include <visioncpp.hpp>

extern "C" {

int native_expression_tree(unsigned char *const Image_1_arg, unsigned char *const out) {
auto device = visioncpp::make_device<visioncpp::backend::sycl, visioncpp::device::gpu>();

// inputs:
std::shared_ptr<unsigned char> Image_1_data(new unsigned char[786432], [](unsigned char *d) { delete[] d; });

{  // compute scope
auto Image_1 = visioncpp::terminal<visioncpp::pixel::U8C3, 512, 512, visioncpp::memory_type::Buffer2D>(Image_1_arg);
auto Image_1_out = visioncpp::terminal<visioncpp::pixel::U8C3, 512, 512, visioncpp::memory_type::Buffer2D>(Image_1_data.get());
auto show_1 = visioncpp::assign(Image_1_out, Image_1);
visioncpp::execute<visioncpp::policy::Fuse, 16, 16, 8, 8>(show_1, device);
}  // compute scope

// outputs:
memcpy(out, Image_1_data.get(), 786432);
  return 0;
}

}  // extern "C"
""")
예제 #3
0
    def test_load_and_show_gpu(self):
        node_in = vp.Image("examples/lena.jpg")
        node_out = vp.show(node_in)
        self.assertEqual(codegen.generate(node_out, "gpu",
                                          use_clang_format=False),
"""#include <opencv2/opencv.hpp>
#include <visioncpp.hpp>

extern "C" {

int native_expression_tree() {
auto device = visioncpp::make_device<visioncpp::backend::sycl, visioncpp::device::gpu>();

// inputs:
std::shared_ptr<unsigned char> Image_1_data(new unsigned char[786432], [](unsigned char *d) { delete[] d; });
cv::Mat show_1_cv(512, 512, CV_8UC(3), Image_1_data.get());

{  // compute scope
cv::Mat Image_1_cv = cv::imread("examples/lena.jpg");
if (!Image_1_cv.data) {
std::cerr << "Could not open or find the image examples/lena.jpg" << std::endl;
return 1;
}
auto Image_1 = visioncpp::terminal<visioncpp::pixel::U8C3, 512, 512, visioncpp::memory_type::Buffer2D>(Image_1_cv.data);
auto Image_1_out = visioncpp::terminal<visioncpp::pixel::U8C3, 512, 512, visioncpp::memory_type::Buffer2D>(Image_1_data.get());
auto show_1 = visioncpp::assign(Image_1_out, Image_1);
visioncpp::execute<visioncpp::policy::Fuse, 16, 16, 8, 8>(show_1, device);
}  // compute scope

// outputs:
cv::namedWindow("show_1", cv::WINDOW_AUTOSIZE);
cv::imshow("show_1", show_1_cv);
cv::waitKey(0);
}

}  // extern "C"
""")
예제 #4
0
 def test_bad_device(self):
     node_in = vp.Image("examples/lena.jpg")
     node_out = vp.show(node_in)
     with self.assertRaises(vp.VisionCppException):
         codegen.generate(node_out, "bad_device", use_clang_format=False)
예제 #5
0
 def test_bad_path(self):
     with self.assertRaises(vp.VisionCppException):
         vp.Image('/not/a/real/file.jpg')
예제 #6
0
 def test_unsupported_image(self):
     with self.assertRaises(vp.VisionCppException):
         vp.Image('foo.gif')
예제 #7
0
    Return contents of unittest data file as a string.

    Args:
        path (str): Relative path.

    Returns:
        string: File contents.

    Raises:
        TestData404: If path doesn't exist.
    """
    with open(data_path(path)) as infile:
        return infile.read()


_in = vp.Image(data_path('lena.jpg'))


class test_visioncpp(TestCase):
    def test_init_path_unchanged(self):
        path = vp.init()
        path2 = vp.init()
        self.assertEqual(path, path2)

    def test_init_path_set(self):
        path = vp.init('README.rst')
        self.assertEqual(path, os.path.abspath('README.rst'))
        path2 = vp.init()
        self.assertEqual(path, path2)

    def test_init_bad_path(self):