Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation的实现好像与官方不一样。 #1

Open
mozheng opened this issue Jan 20, 2021 · 1 comment
Open

Segmentation的实现好像与官方不一样。 #1

mozheng opened this issue Jan 20, 2021 · 1 comment

Comments

@mozheng
Copy link

mozheng commented Jan 20, 2021

问个问题,官方demo的Segmentation不是你这样写的。你这样写是什么意思?实验证明这么写的确会减缓启动时噪点多的问题,但也会失去部分精度。

def Segmentation(self, uint8_t[:, :] image):        
        cdef int width = image.shape[1]
        cdef int height = image.shape[0]
        
        # cdef np.ndarray[uint8_t, ndim=2] segmentation = np.zeros([width, height], dtype=np.uint8)
        cdef uint8_t[:, :] segmentation_map = np.empty((height, width), dtype=np.uint8)  # 官方的 segmentation_map每次调用不是申请为0的区域,而是复用上一次的segmentation_map
        
        cdef uint8_t *image_data_ptr = &image[0, 0]
        cdef uint8_t *segmentation_map_ptr = &segmentation_map[0, 0]
        
        # call C function
        cdef int32_t back
        back = c_vibe.libvibeModel_Sequential_Segmentation_8u_C1R(self.model, image_data_ptr, segmentation_map_ptr)
        # Error: need convert segmentation_map to numpy.array
        # return segmentation_map
        return np.asarray(segmentation_map)

下面是官方的实现

while ((char)keyboard != 'q' && (char)keyboard != 27) {
    /* Read the current frame. */
    if (!capture.read(frame)) {
      cerr << "Unable to read next frame." << endl;
      cerr << "Exiting..." << endl;
      exit(EXIT_FAILURE);
    }

    if ((frameNumber % 100) == 0) { cout << "Frame number = " << frameNumber << endl; }

    if (frameNumber == 1) {
      segmentationMap = Mat(frame.rows, frame.cols, CV_8UC1);
      model = (vibeModel_Sequential_t*)libvibeModel_Sequential_New();
      libvibeModel_Sequential_AllocInit_8u_C3R(model, frame.data, frame.cols, frame.rows);
    }

    libvibeModel_Sequential_Segmentation_8u_C3R(model, frame.data, segmentationMap.data);
    libvibeModel_Sequential_Update_8u_C3R(model, frame.data, segmentationMap.data);
    medianBlur(segmentationMap, segmentationMap, 3); /* 3x3 median filtering */

  }
@232525
Copy link
Owner

232525 commented Jan 20, 2021

你看一下这一行/~https://github.com/232525/ViBe.Cython/blob/master/lib_vibe/vibe-background-sequential.c#L321 ,官方实现应该也不是复用上一次结果,好像是把数据清成1,segmentation_map是每一次调用模型获取前景分割的结果,不至于需要复用的,我改的时候只是单纯的为了可以python调用这个函数,没考虑太多。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants