Esempio n. 1
0
    def test_parameter(self):
        c = vx.CreateContext()
        g = vx.CreateGraph(c)
        img = vx.CreateImage(c, 640, 480, vx.DF_IMAGE_U8)
        dx = vx.CreateImage(c, 640, 480, vx.DF_IMAGE_S16)
        dy = vx.CreateImage(c, 640, 480, vx.DF_IMAGE_S16)
        node = vx.Sobel3x3Node(g, img, dx, dy)

        param = vx.GetParameterByIndex(node, 0)
        assert vx.GetStatus(vx.reference(param)) == vx.SUCCESS
        assert vx.QueryReference(vx.reference(param), vx.REF_ATTRIBUTE_TYPE, 'vx_enum') == (vx.SUCCESS, vx.TYPE_PARAMETER)
        s, v = vx.QueryParameter(param, vx.PARAMETER_ATTRIBUTE_REF, "vx_reference")
        assert s == vx.SUCCESS
        assert v == img

        assert vx.SetParameterByIndex(node, 0, vx.reference(dx)) == vx.SUCCESS
        s, v = vx.QueryParameter(param, vx.PARAMETER_ATTRIBUTE_REF, "vx_reference")
        assert s == vx.SUCCESS
        assert v == dx

        assert vx.SetParameterByReference(param, vx.reference(dy)) == vx.SUCCESS
        s, v = vx.QueryParameter(param, vx.PARAMETER_ATTRIBUTE_REF, "vx_reference")
        assert s == vx.SUCCESS
        assert v == dy

        assert vx.ReleaseParameter(param) == vx.SUCCESS
        assert vx.ReleaseContext(c) == vx.SUCCESS
Esempio n. 2
0
def Sobel3x3Node(graph, input_img, output_x=None, output_y=None):
    if output_x is None:
        output_x = Image(graph, input_img.get_width(), input_img.get_height())
    if output_y is None:
        output_y = Image(graph, input_img.get_width(), input_img.get_height())
    vx.Sobel3x3Node(graph.graph, input_img.image, output_x.image,
                    output_y.image)
    return output_x, output_y
Esempio n. 3
0
def main():
    #   go_pro = GoProCamera()
    #    go_pro.shoot_still()
    name = '3'
    pil_img = Image.open('3.JPG')  #go_pro.get_image()
    pil_img = pil_img.convert('L')
    pil_img = pil_img.resize((600, 800))
    # OpenVX
    context = vx.CreateContext()
    graph = vx.CreateGraph(context)
    img_w = pil_img.width
    img_h = pil_img.height
    vxImage = pil2vx(context, pil_img)
    grey = vx.CreateImage(context, img_w, img_h, vx.DF_IMAGE_U8)
    images = [
        vx.CreateImage(context, img_w, img_h, vx.DF_IMAGE_S16),
        vx.CreateImage(context, img_w, img_h, vx.DF_IMAGE_S16),
        vx.CreateImage(context, img_w, img_h, vx.DF_IMAGE_S16),
        vx.CreateImage(context, img_w, img_h, vx.DF_IMAGE_U8),
        vx.CreateImage(context, img_w, img_h, vx.DF_IMAGE_U8),
        vx.CreateImage(context, img_w, img_h, vx.DF_IMAGE_U8)
    ]
    vx.Sobel3x3Node(graph, vxImage, images[1], images[2])
    vx.MagnitudeNode(graph, images[1], images[2], images[0])
    vx.PhaseNode(graph, images[1], images[2], images[3])
    threshold = vx.CreateThreshold(context, vx.THRESHOLD_TYPE_RANGE,
                                   vx.TYPE_UINT8)
    #vx.SetThresholdAttribute(threshold,vx.THRESHOLD_ATTRIBUTE_THRESHOLD_up, 10, "vx_uint32")
    vx.SetThresholdAttribute(threshold, vx.THRESHOLD_ATTRIBUTE_THRESHOLD_LOWER,
                             10, "vx_uint32")
    vx.SetThresholdAttribute(threshold, vx.THRESHOLD_ATTRIBUTE_THRESHOLD_UPPER,
                             100, "vx_uint32")
    print vx.QueryThreshold(threshold, vx.THRESHOLD_ATTRIBUTE_THRESHOLD_UPPER,
                            "vx_uint32")
    print vx.QueryThreshold(threshold, vx.THRESHOLD_ATTRIBUTE_THRESHOLD_LOWER,
                            "vx_uint32")
    vx.CannyEdgeDetectorNode(graph, vxImage, threshold, 3, vx.NORM_L1,
                             images[4])

    status = vx.VerifyGraph(graph)
    if status == vx.SUCCESS:
        status = vx.ProcessGraph(graph)
    print status

    mag = vx2np(images[0])
    phase = vx2np(images[3])
    canny = vx2np(images[4])
    pil_img.save(name + '_input.jpg')
    Image.fromarray(mag).save(name + '_magnitude.jpg')
    Image.fromarray(canny).save(name + '_canny.jpg')
    pil_img.show('Source')
    if True:  # Show image using PIL
        pil_img.show()
        Image.fromarray(mag).show('Magnitued')
        Image.fromarray(phase).show('Phase')
        Image.fromarray(canny).show('Canny edge detector')
Esempio n. 4
0
 def test_sobel(self):
     c = vx.CreateContext()
     img = vx.CreateImage(c, 640, 480, vx.DF_IMAGE_U8)
     dx = vx.CreateImage(c, 640, 480, vx.DF_IMAGE_S16)
     dy = vx.CreateImage(c, 640, 480, vx.DF_IMAGE_S16)
     g = vx.CreateGraph(c)
     node = vx.Sobel3x3Node(g, img, dx, dy)
     assert vx.GetStatus(vx.reference(node)) == vx.SUCCESS
     assert vx.VerifyGraph(g) == vx.SUCCESS
     assert vx.ProcessGraph(g) == vx.SUCCESS
     # FIXME: assert something
     assert vx.ReleaseContext(c) == vx.SUCCESS
Esempio n. 5
0
    def test_graph(self):
        c = vx.CreateContext()
        g = vx.CreateGraph(c)
        assert vx.GetStatus(vx.reference(g)) == vx.SUCCESS
        assert vx.QueryReference(vx.reference(g), vx.REF_ATTRIBUTE_TYPE, 'vx_enum') == (vx.SUCCESS, vx.TYPE_GRAPH)
        assert vx.IsGraphVerified(g) == vx.false_e
        assert vx.QueryGraph(g, vx.GRAPH_ATTRIBUTE_NUMNODES, 'vx_uint32') == (vx.SUCCESS, 0)

        img = vx.CreateImage(c, 640, 480, vx.DF_IMAGE_U8)
        dx = vx.CreateImage(c, 640, 480, vx.DF_IMAGE_S16)
        dy = vx.CreateImage(c, 640, 480, vx.DF_IMAGE_S16)
        node = vx.Sobel3x3Node(g, img, dx, dy)
        assert vx.VerifyGraph(g) == vx.SUCCESS
        assert vx.ProcessGraph(g) == vx.SUCCESS
        assert vx.ScheduleGraph(g) == vx.SUCCESS
        assert vx.WaitGraph(g) == vx.SUCCESS

        p = vx.GetParameterByIndex(node, 0)
        assert vx.AddParameterToGraph(g, p) == vx.SUCCESS
        p2 = vx.GetGraphParameterByIndex(g, 0)
        assert vx.SetGraphParameterByIndex(g, 0, vx.reference(dx)) == vx.SUCCESS
        assert vx.VerifyGraph(g) != vx.SUCCESS
        assert vx.SetGraphParameterByIndex(g, 0, vx.reference(img)) == vx.SUCCESS
        assert vx.VerifyGraph(g) == vx.SUCCESS
        assert vx.IsGraphVerified(g) == vx.true_e

        def callback(node):
            callback.called = True
            return vx.SUCCESS

        assert vx.AssignNodeCallback(node, callback) == vx.SUCCESS
        assert vx.ProcessGraph(g) == vx.SUCCESS
        assert callback.called

        def callback(node):
            raise TypeError('Escaping from callback')
            return vx.SUCCESS

        assert vx.AssignNodeCallback(node, callback) != vx.SUCCESS
        assert vx.AssignNodeCallback(node, None) == vx.SUCCESS
        assert vx.AssignNodeCallback(node, callback) == vx.SUCCESS
        assert vx.VerifyGraph(g) == vx.SUCCESS
        assert vx.ProcessGraph(g) != vx.SUCCESS

        img = vx.CreateVirtualImage(g, 640, 480, vx.DF_IMAGE_RGB)
        assert vx.GetStatus(vx.reference(img)) == vx.SUCCESS

        assert vx.ReleaseGraph(g) == vx.SUCCESS
        assert vx.ReleaseContext(c) == vx.SUCCESS
Esempio n. 6
0
    def test_delay(self):
        c = vx.CreateContext()
        img = vx.CreateImage(c, 640, 480, vx.DF_IMAGE_RGB)
        delay = vx.CreateDelay(c, vx.reference(img), 3)
        assert vx.GetStatus(vx.reference(delay)) == vx.SUCCESS
        assert vx.QueryReference(vx.reference(delay), vx.REF_ATTRIBUTE_TYPE, 'vx_enum') == (vx.SUCCESS, vx.TYPE_DELAY)
        assert vx.QueryDelay(delay, vx.DELAY_ATTRIBUTE_SLOTS, 'vx_size') == (vx.SUCCESS, 3)
        ref0 = vx.GetReferenceFromDelay(delay, 0)
        ref1 = vx.GetReferenceFromDelay(delay, 1)
        ref2 = vx.GetReferenceFromDelay(delay, 2)
        g = vx.CreateGraph(c)
        node = vx.Sobel3x3Node(g, vx.from_reference(ref0), vx.from_reference(ref1), vx.from_reference(ref2))

        param = vx.GetParameterByIndex(node, 1)
        s, v = vx.QueryParameter(param, vx.PARAMETER_ATTRIBUTE_REF, "vx_reference")
        assert s == vx.SUCCESS
        assert v == ref1
        assert vx.AgeDelay(delay) == vx.SUCCESS
        s, v = vx.QueryParameter(param, vx.PARAMETER_ATTRIBUTE_REF, "vx_reference")
        assert s == vx.SUCCESS
        assert v == ref0

        assert vx.ReleaseDelay(delay) == vx.SUCCESS
        assert vx.ReleaseContext(c) == vx.SUCCESS
Esempio n. 7
0
from pyvx import vx

context = vx.CreateContext()
images = [
    vx.CreateImage(context, 640, 480, vx.DF_IMAGE_UYVY),
    vx.CreateImage(context, 640, 480, vx.DF_IMAGE_S16),
    vx.CreateImage(context, 640, 480, vx.DF_IMAGE_U8),
]
graph = vx.CreateGraph(context)
virts = [
    vx.CreateVirtualImage(graph, 0, 0, vx.DF_IMAGE_VIRT),
    vx.CreateVirtualImage(graph, 0, 0, vx.DF_IMAGE_VIRT),
    vx.CreateVirtualImage(graph, 0, 0, vx.DF_IMAGE_VIRT),
    vx.CreateVirtualImage(graph, 0, 0, vx.DF_IMAGE_VIRT),
]
vx.ChannelExtractNode(graph, images[0], vx.CHANNEL_Y, virts[0])
vx.Gaussian3x3Node(graph, virts[0], virts[1])
vx.Sobel3x3Node(graph, virts[1], virts[2], virts[3])
vx.MagnitudeNode(graph, virts[2], virts[3], images[1])
vx.PhaseNode(graph, virts[2], virts[3], images[2])
status = vx.VerifyGraph(graph)

if status == vx.SUCCESS:
    status = vx.ProcessGraph(graph)
else:
    print("Verification failed.")
vx.ReleaseContext(context)