SHOW:
|
|
- or go back to the newest paste.
| 1 | def TCPfin(self,imgprevstr): | |
| 2 | timenow = datetime.now() #get current time | |
| 3 | ||
| 4 | #quick | |
| 5 | splitimgprevstr = imgprevstr.split(',',11)
| |
| 6 | splitimgdata = splitimgprevstr[11] #qstring with 540000 chars | |
| 7 | imgwidth = int(splitimgprevstr[9]) | |
| 8 | imgheight = int(splitimgprevstr[10]) | |
| 9 | ||
| 10 | rgbArray = np.zeros((imgwidth,imgheight,3), 'uint8') | |
| 11 | #slow from here | |
| 12 | ||
| 13 | for ih in range(0,imgheight,1): # takes around 220ms per loop (3 loops for the 3 RGB channels | |
| 14 | for iw in range(0,imgwidth,1): | |
| 15 | curpixelR = splitimgdata.mid(iw*6+ih*imgwidth*6, 2) #get a pair of chars from the qstring | |
| 16 | rgbArray[iw,ih,0] = (curpixelR.toInt(16))[0] #convert the ascii hex qstring into an int | |
| 17 | ||
| 18 | for ih in range(0,imgheight,1): | |
| 19 | for iw in range(2,imgwidth,1): | |
| 20 | curpixelG = splitimgdata.mid(iw*6+ih*imgwidth*6, 2) | |
| 21 | rgbArray[iw,ih,1] = (curpixelG.toInt(16))[0] | |
| 22 | ||
| 23 | for ih in range(0,imgheight,1): | |
| 24 | for iw in range(4,imgwidth,1): | |
| 25 | curpixelB = splitimgdata.mid(iw*6+ih*imgwidth*6, 2) | |
| 26 | rgbArray[iw,ih,2] = (curpixelB.toInt(16))[0] | |
| 27 | ||
| 28 | #Total execution time 656ms | |
| 29 | # quick | |
| 30 | fintime = self.millis(timenow) | |
| 31 | print fintime | |
| 32 | previmg = Image.fromarray(rgbArray) | |
| 33 | previmg = previmg.rotate(90) | |
| 34 | ||
| 35 | ||
| 36 | ||
| 37 | self.parent.slot_testcall(previmg) #image sent to GUI module to update screen |