在带有休息条件的x,y循环中循环x + 1,y + 1

i have an opencv image read as x and y its all black with some pixels that are img[x,y,0]>45 (blue) i have a code that follows every blue pixel and turns it red reading column by by column and line by line with a for loop inside another for loop y and x. But i want to implement a second method that reads the neighboring pixels if x,y is blue the check the neighbor and extend it to new x-1 and new x+1 and new y-1,y+1, from x-1 to x+1 and y-1 to y+1 u will find an image link to docs about the first method and i hope u will help with the second https://drive.google.com/file/d/1BOMP0PVlO05FIAQMNPAJkGNbuxmnMxKm/view?usp=sharing. here is the code:enter code here

def SimulateB():

    global dimx
    global dimy
    global width
    global height
    global Matrix
    #simwindow=Toplevel()                               #  THIS BLOCK DOWN 
    #simwindow.geometry("600x600")                     #THE END WAS MEANT
    src=cv2.imread('result.jpg')
    btx=width/2
    bty=height/2
    thickrec=50
    #dim=(width, height)
    img=cv2.resize(src, None,fx=0.5,fy=0.5, interpolation=cv2.INTER_AREA)
    cv2.rectangle(img, (0,0), (btx,bty), (255,255,255), thickrec)
    #cv2.imshow('anim',img)
    #font = cv2.FONT_HERSHEY_SIMPLEX
    #cv2.putText(img,  'Simulation Method: Linear Cutt.  Simulation Size: 1/2 Original. Border: White 25 Px ie 25 mm On Materiel. Lazer head: process Red', (25,10), font, 0.5,(0,0,0),1 ,cv2.LINE_AA) 
    for y in range ((thickrec/2)+1, (bty-thickrec/2)-1, 1):

                    cv2.imshow('OpenCv Cutt Simulation V0.01', img)

                    for x in range ((thickrec/2)+1, (btx-thickrec/2)-1, 1):
                            e=y
                            f=x
                            #print('this not blue')
                            if int(img[x, y, 0])>45:
                                    print('initial blue', y,x)      
                                    #img[x, y ,0]=0
                                    #img[x, y, 1]=0
                                    #img[x, y, 2]=255

                                    if e>(thickrec/2)+1 and e<(bty-thickrec/2)-1 and f>(thickrec/2)+1 and f<(btx-thickrec/2)-1:

                                              for e in range (e-1,e+1):
                                                    for f in range (f-1, f+1):
                                                            if  int(img[f, e, 0])>45:
                                                                    img[f,e,0]=0
                                                                    img[f,e,1]=0
                                                                    img[f,e,2]=255
                                                                    print("inside loop",e,f)



                    cv2.waitKey(1) & 0xff == ord('q')


         cv2.destroyAllWindows()
即使没有起步器也不会在内部循环
评论