1

I am doing image processing but here I a facing problem in my code for open cv part. Here is the code where error is been there. I have marked the error in the code.

if event.type == MOUSEMOTION and iswriting:
  xcord,ycord = event.pos
  pygame.draw.circle(DISPLAYSURFACE, WHITE, (xcord, ycord), 4.0)
  number_xcord.append(xcord)
  number_ycord.append(ycord)

if event.type == MOUSEBUTTONDOWN:
  iswriting = True

if event.type == MOUSEBUTTONUP:
  iswriting = False
  number_xcord = sorted(number_xcord)
  number_ycord = sorted(number_ycord)

  rect_min_x, rect_max_x = max(number_xcord[0]-BOUNDARYINC, 0), min(WINDOWSIZEX, number_xcord[-1]+BOUNDARYINC)
  rect_min_y, rect_max_y = max(number_ycord[0]-BOUNDARYINC, 0), min(WINDOWSIZEY, number_ycord[-1]+BOUNDARYINC)

  number_xcord = []
  number_ycord = []
  img_arr = np.array(pygame.PixelArray(DISPLAYSURFACE))
  if IMAGESAVE:
    cv2.imwrite("image.png")
    inmg_cnt +=1

  if PREDICT:
    image = cv2.resize(img_arr, (28,28))  <----- Error Here
    image = np.pad(image, (10,10), 'constant', constant_value = 0)
    image = cv2.resize(image, (28,28))/WHITE_INT
    label = str(LABELS[np.argmax(MODEL.predict(image.reshape(1,28,28,1)))]).title()
    pygame.draw.rect(DISPLAYSURFACE, RED, (rect_min_x, rect_min_y, rect_max_x-rect_min_y,
                                           rect_max_y-rect_min_y), 3)

  if event.type == KEYDOWN: 
   if event.unicode == 'N':
     DISPLAYSURFACE.fill(BLACK)

pygame.display.update()

The error shown is this

cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'resize'
> Overload resolution failed:
>  - src data type = 8 is not supported
>  - Expected Ptr<cv::UMat> for argument 'src'

Please help me out. I have no clue what to do now.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Tanmay joshi
  • 15
  • 1
  • 4
  • 2
    I think that means you have 2 channel 8-bit data and resize will not handle 2 channel images. I think it needs one or 3 channels. See http://ninghang.blogspot.com/2012/11/list-of-mat-type-in-opencv.html. I will defer to the experts to correct this statement. – fmw42 Mar 22 '22 at 00:19
  • I'd conclude the same. why is that pygame surface just 2-channel? strange. odd, even. -- I've added pygame and numpy tags and sharpened the title – Christoph Rackwitz Jul 03 '22 at 14:26

0 Answers0