def __getBackGround2(self, threshold, preImage): """ Method number 3 to detect the background pixels. The background is detected of the local Image using the given preImage. For this it is calculed the difference between them. @type threshold: int @param preImage: Image used to compare the differences @type preImage: IplImage @return: As first parameter the original image changing the different pixel to black pixel. As Second parameter a IplImage in Gray Scale where the differences are white pixels. After this can be used as mask. """ differenceI = cv.CreateImage(cv.GetSize(self.__image), cv.IPL_DEPTH_8U, 3) grayI = cv.CreateImage(cv.GetSize(differenceI), cv.IPL_DEPTH_8U, 1) cv.AbsDiff(self.__image, preImage, differenceI) cv.CvtColor(differenceI, grayI, cv.CV_BGR2GRAY) cv.Threshold(grayI, grayI, threshold, 255, cv.CV_THRESH_BINARY) cv.Smooth(grayI, grayI, cv.CV_MEDIAN, 5) cv.Smooth(grayI, grayI, cv.CV_GAUSSIAN, 5) cv.SetZero(differenceI) cv.Add(self.__image, differenceI, differenceI, grayI) return differenceI, grayI
def __getBackGround(self, threshold, color): """ Method number 1 to detect the background pixels. The background is detected of the local Image using given color. For this it is calculed the difference between local Image and another image set up the given color only. @param threshold: Edge to detect the color background @type threshold: int @param color: Color used to detect background @type color: cvScalar @return: As first parameter the original image changing the different pixel to black pixel. As Second parameter a IplImage in Gray Scale where the differences are white pixels. After this can be used as mask. """ differenceI = cv.CreateImage(cv.GetSize(self.__image), cv.IPL_DEPTH_8U, 3) grayI = cv.CreateImage(cv.GetSize(self.__image), cv.IPL_DEPTH_8U, 1) backgroundI = cv.CreateImage(cv.GetSize(self.__image), cv.IPL_DEPTH_8U, 3) cv.Set(backgroundI, color) cv.AbsDiff(self.__image, backgroundI, differenceI) cv.CvtColor(differenceI, grayI, cv.CV_BGR2GRAY) cv.Smooth(grayI, grayI, cv.CV_BLUR, 5) cv.Smooth(grayI, grayI, cv.CV_MEDIAN, 5) cv.Threshold(grayI, grayI, threshold, 255, cv.CV_THRESH_BINARY) cv.SetZero(differenceI) cv.And(self.__image, self.__image, differenceI, grayI) return differenceI, grayI
def applyFilter(self, typeF): """ Applies filter to the stored image @param typeF: The type the filter to apply @type typeF: FrameFilter {GAUSSIAN,MEDIAN,CANNY} """ if typeF == FrameFilter.GAUSSIAN: cv.Smooth(self.__image, self.__image, cv.CV_GAUSSIAN, 9, 9) elif typeF == FrameFilter.MEDIAN: cv.Smooth(self.__image, self.__image, cv.CV_MEDIAN, 9) elif typeF == FrameFilter.CANNY: frame2 = cv.CreateImage(cv.GetSize(self.__image), 8, 1) cv.CvtColor(self.__image, frame2, cv.CV_BGR2GRAY) cv.Canny(frame2, frame2, 70.0, 140.0, 3) cv.CvtColor(frame2, self.__image, cv.CV_GRAY2BGR)
def __getBackGround1(self, threshold, color): """ Method number 2 to detect the background pixels. The background is detected of the local Image using given color. For this it is calculed the difference between local Image and another image set up the given color only in each one channel of color. @param threshold: Edge to detect the color background @type threshold: int @param color: Color used to detect background @type color: cvScalar @return: As first parameter the original image changing the different pixel to black pixel. As Second parameter a IplImage in Gray Scale where the differences are white pixels. After this can be used as mask. """ backgroundI = cv.CreateImage(cv.GetSize(self.__image), cv.IPL_DEPTH_8U, 3) cv.Set(backgroundI, color) i0, i1, i2, i3, b0, b1, b2, b3, d0, d1, d2, d3 = tuple([ cv.CreateImage(cv.GetSize(self.__image), cv.IPL_DEPTH_8U, 1) for i in range(12) ]) differenceI = cv.CreateImage(cv.GetSize(self.__image), cv.IPL_DEPTH_8U, 3) grayI = cv.CreateImage(cv.GetSize(differenceI), cv.IPL_DEPTH_8U, 1) cv.Split(self.__image, i0, i1, i2, None) cv.Split(backgroundI, b0, b1, b2, None) cv.AbsDiff(i0, b0, d0) cv.AbsDiff(i1, b1, d1) cv.AbsDiff(i2, b2, d2) cv.Threshold(d0, d0, threshold, 255, cv.CV_THRESH_BINARY) cv.Threshold(d1, d1, threshold, 255, cv.CV_THRESH_BINARY) cv.Threshold(d2, d2, threshold, 255, cv.CV_THRESH_BINARY) cv.Merge(d0, d1, d2, None, differenceI) cv.CvtColor(differenceI, grayI, cv.CV_BGR2GRAY) cv.Smooth(grayI, grayI, cv.CV_BLUR, 5) cv.Smooth(grayI, grayI, cv.CV_MEDIAN, 5) cv.Threshold(grayI, grayI, threshold, 255, cv.CV_THRESH_BINARY) cv.SetZero(differenceI) cv.Add(self.__image, differenceI, differenceI, grayI) return differenceI, grayI
def __getThresholdImage1(self, threshold, color): """ Tecnique number 2 to detect the current possition of a specific color in the local image. @param threshold: Allowed threshold to search. @param color: Value of the color to search. @return The mask where is found the intervale of chosen colours. """ differenceI = cv.CreateImage(cv.GetSize(self.__image), cv.IPL_DEPTH_8U, 3) grayI = cv.CreateImage(cv.GetSize(differenceI), cv.IPL_DEPTH_8U, 1) backgroundI = cv.CreateImage(cv.GetSize(self.__image), cv.IPL_DEPTH_8U, 3) cv.Set(backgroundI, color) cv.AbsDiff(self.__image, backgroundI, differenceI) cv.CvtColor(differenceI, grayI, cv.CV_BGR2GRAY) cv.Smooth(grayI, grayI, cv.CV_BLUR, 5) cv.Smooth(grayI, grayI, cv.CV_MEDIAN, 5) cv.Threshold(grayI, grayI, threshold, 255, cv.CV_THRESH_BINARY) cv.Not(grayI, grayI) return grayI