Open CV -unable to execute python code having cv2

别来无恙 提交于 2019-12-11 17:49:59

问题


I'm using CL-SOM-AM57x - TI AM5728 / AM5718 System-on-Module and load it with Ti's matrix app launcher based on Linux Debian. I am trying to develop a python app which can be launched from TI Matrix GUI. With simple python code the app works fine in Terminal(loads and import openCV and numpy) but when I launch and run the App(have created Icon and the app is executing) from TI matrix GUI which doesn't work properly and shows some errors/warnings in terminal. The App is opening and Prints on screen values but it looks like the OpenCV module and numpy is not loading or working properly.

So the issue is that the same code works on Terminal but not when launched in an App from TI matrix GUI.

sample code:

import numpy as np

import cv2

img = cv2.imread('rgb.jpg')

np_image = np.array(img)

num_list = np_image.tolist()

str1 =str(num_list)

print( len(str1))

print(str1)

Shell script #!/bin/bash

/usr/bin/python2.7 /usr/share/matrix-gui-2.0/apps/ex_application/1.py

Errors in Terminal:

[ 6860.067644] omap_hwmod: mmu0_dsp2: _wait_target_disable failed

[ 6860.073549] omap-iommu 41501000.mmu: 41501000.mmu: version 3.0

[ 6860.079683] omap-iommu 41502000.mmu: 41502000.mmu: version 3.0

[ 6860.093489] omap_hwmod: mmu0_dsp1: _wait_target_disable failed

[ 6860.099385] omap-iommu 40d01000.mmu: 40d01000.mmu: version 3.0

[ 6860.105342] omap-iommu 40d02000.mmu: 40d02000.mmu: version 3.0

[ 6870.136544] omap_hwmod: mmu1_dsp1: _wait_target_disable failed

[ 6870.149842] omap_hwmod: mmu0_dsp1: _wait_target_disable failed

[ 6870.163511] omap_hwmod: mmu1_dsp2: _wait_target_disable failed

[ 6870.176696] omap_hwmod: mmu0_dsp2: _wait_target_disable failed

Output of App:

4
None

But if P run the same code in terminal, using the same board it works fine and output gives a matrix of array. I need to run this on an App in matrix GUI and would want to get the same Array as output. Any suggestions?


回答1:


I'm puzzled by what you expect that code to do. img is already an np.ndarray. Creating an identical copy chews up double the memory. (You can verify that it is identical via executing np.all(img == np_image) from a Python REPL. It should respond True.) Converting one of those to a Python list chews up even more memory, and converting the Python list into a string chews up a lot.

I'm not acquainted with the board you're using, but a quick search suggests that it has limited RAM. Could it be that what you're seeing is a side-effect of running out of memory on the board?




回答2:


I found the solution . "Even if the image path is wrong, it won’t throw any error, but print img will give you None".Which is mentioned in the openCV documentation . So i changed the line

img = cv2.imread('rgb.jpg')

to

img = cv2.imread('/usr/share/matrix-gui-2.0/apps/ex_application/rgb.jpg')
#input full directory



来源:https://stackoverflow.com/questions/53021059/open-cv-unable-to-execute-python-code-having-cv2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!