data_acquired = pyqtSignal(np.ndarray)self.data_acquired.connect(self.RepeatPlot)
# the above 2 lines are defined immediately after class is defined and within __init__(),and not at this location as pasted here
self.acq_thread = Thread(target = self.camera.LiveAquisition,args =(self.data_acquired.emit,))
self.acq_thread.start()self.Display = GraphicsView(self.centralwidget)
self.Display.setGeometry(QtCore.QRect(30, 130, 461, 541))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.Display.setFont(font)
self.Display.setMouseTracking(True)
self.Display.setAutoFillBackground(False)
self.Display.setObjectName("Display")
self.l = GraphicsLayout()
self.vb = self.l.addViewBox()
self.Display.setCentralItem(self.l)
self.img = ImageItem(border='w')
self.vb.addItem(self.img)@pyqtSlot(np.ndarray)
def RepeatPlot(self,image):
self.I = image
self.img.setImage(self.I)def LiveAquisition(self,callback):
# Initialisation and declaration of variables/paramters
image = np.zeros(((self.aoiWidth-self.AOILeft)/self.hbin, (self.aoiHeight-self.AOITop)/self.vbin), dtype=np.uint16)
image = np.zeros(((self.aoiWidth)/self.hbin, (self.aoiHeight)/self.vbin), dtype=np.uint16)
self.i = 0
start = time.time()
while self.i <self.framecount:
pBuf = <unsigned char *>calloc(sizeInBytes, sizeof(unsigned char))
AT_QueueBuffer(<AT_H>self.cameraHandle, pBuf, sizeInBytes)
#print "Frame number is :",
#print self.i
timeOut = <unsigned int>(3 * self.exposureTime * 1000)
if timeOut < 500:
timeOut = 500
response_code = AT_WaitBuffer(<AT_H>self.cameraHandle, &returnBuffer, &BufSize, timeOut)
Py_INCREF(dtype)
image = PyArray_NewFromDescr(<PyTypeObject *> np.ndarray, np.dtype('<H'), 2,dims, strides,pBuf, np.NPY_C_CONTIGUOUS,None)
callback(image)
time.sleep(0.01)
free(pBuf)
self.i = self.i+1
copy2WCStr("AcquisitionStop",string3)
AT_Command(<AT_H>self.cameraHandle, string3)
AT_Flush(<AT_H>self.cameraHandle)
stop = time.time()
print "Time:",
print stop-start
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/9369949e-3198-4b8c-ad35-d9d012f52094%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/4fbf36df-7276-4d8a-8e83-9caaba5dce5c%40googlegroups.com.
I'm guessing the issue is that you create an ndarray from pBuf, and then immediately delete pBuf after emitting the signal. This frees up the memory in use by the ndarray, causing it to be partially overwritten by the time it is displayed in the gui thread. An easy way to check this might be to send a copy of the array: `callback(image.copy())`.However if you want to avoid the performance overhead of copying (and also avoid memory leaks), then you need to understand how to transfer "ownership" of the memory held in pBuf to numpy. I am not familiar enough with the numpy C API or cython to make a suggestion there.Side question: is there a reason you are using cython instead of ctypes? For camera acquisition, I would imagine the latter is easier and just as fast.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/CACZXET-ePn2NEWKQOZjX7E%3DVVYrp5AD5_WH1on%3DUzMhe5EX1BA%40mail.gmail.com.