예제 #1
0
            sq = cv2.selectROI('Choose object', gray)
            cv2.destroyWindow('Choose object')

            imag_mask = gray[sq[1]:sq[1] + sq[3], sq[0]:sq[0] + sq[2]]
            print(np.shape(imag_mask))
            hist_r, bins_r = np.histogram(imag_mask[:, :],
                                          bins=bins,
                                          range=(0, 255),
                                          density=True)
            #hist_b, bins_b = np.histogram(imag_mask[:,:,1], bins=bins, range=(0, 255), density=True)
            #hist_g, bins_b = np.histogram(imag_mask[:,:,2], bins=bins, range=(0, 255), density=True)
            print("Histogram made")

            # Initialise Particle Filter
            PF = ParticleFilter(N, hist_r, max_x, max_y, bins, dt, Q, R)
            s = PF.state_init()
            particle_frame[s[0, :], s[1, :]] = [0, 255, 0]

            # plt.subplot(231), plt.plot(hist_r), plt.title('Red')
            # plt.subplot(232), plt.plot(hist_g), plt.title('Green')
            # plt.subplot(233), plt.plot(hist_b), plt.title('Blue')
            # plt.show()

        # Press Q on keyboard to  exit
        if cv2.waitKey(25) & 0xFF == ord('q'):
            break

# Break the loop
    else:
        break