Hello. I am looking to implement a program that opens a PyQt Drag and Drop GUI where I can drag a image file and it will show the image with detections on screen. I am doing the detection part exactly like the detect-net.py does it but I keep getting error: detections = net.Detect(img) Exception: jetson.utils – function wasn’t passed a valid cudaImage or cudaMemory object
Below is my code
import sys
import os
from PyQt4 import QtGui, QtCore
import jetson.inference
import jetson.utils
class TestListView(QtGui.QListWidget):
def __init__(self, type, parent=None):
super(TestListView, self).__init__(parent)
self.setAcceptDrops(True)
self.setIconSize(QtCore.QSize(72, 72))
def dragEnterEvent(self, event):
if event.mimeData().hasUrls:
event.accept()
else:
event.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
else:
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
links = []
for url in event.mimeData().urls():
links.append(str(url.toLocalFile()))
net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5)
input = jetson.utils.videoSource(str(url.toLocalFile()))
display = jetson.utils.videoOutput("display://0")
while display.IsStreaming():
img = input.Capture
detections = net.Detect(img)
display.Render(img)
self.emit(QtCore.SIGNAL("dropped"), links)
else:
event.ignore()
class MainForm(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainForm, self).__init__(parent)
self.view = TestListView(self)
self.connect(self.view, QtCore.SIGNAL("dropped"), self.pictureDropped)
self.setCentralWidget(self.view)
def pictureDropped(self, l):
for url in l:
if os.path.exists(url):
print(url)
icon = QtGui.QIcon(url)
pixmap = icon.pixmap(72, 72)
icon = QtGui.QIcon(pixmap)
item = QtGui.QListWidgetItem(url, self.view)
item.setIcon(icon)
item.setStatusTip(url)
def main():
app = QtGui.QApplication(sys.argv)
form = MainForm()
form.show()
app.exec_()
if __name__ == '__main__':
main()