我需要用于计数图像中细胞数量的代码,并且只应计数粉红色的细胞。我使用了阈值化和分水岭方法。
import cv2
from skimage.feature import peak_local_max
from skimage.morphology import watershed
from scipy import ndimage
import numpy as np
import imutils
image = cv2.imread("cellorigin.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cv2.imshow("Thresh", thresh)
D = ndimage.distance_transform_edt(thresh)
localMax = peak_local_max(D, indices=False, min_distance=20,
labels=thresh)
cv2.imshow("D image", D)
markers = ndimage.label(localMax, structure=np.ones((3, 3)))[0]
labels = watershed(-D, markers, mask=thresh)
print("[INFO] {} unique segments found".format(len(np.unique(labels)) - 1))
for label in np.unique(labels):
# if the label is zero, we are examining …Run Code Online (Sandbox Code Playgroud) python opencv image-processing computer-vision image-segmentation
我需要代码来检测缩放和旋转不变的对象。图片中有 8 个笔式驱动器,它们的大小和旋转角度各不相同。我只能使用 matchTemplate() 检测到几个笔式驱动器。我需要带有 SURF、BRIEF 或任何其他可以检测所有 8 个笔式驱动器的算法的代码。我搜索了其他问题,它们只提供了想法,但没有 Python 代码。
可以使用的包有:
模板:
输出:
代码 :
import cv2
import numpy as np
image1 = cv2.imread("scale_ri.jpg")
scale_percent = 60 # percent of original size
width = int(image1.shape[1] * scale_percent / 100)
height = int(image1.shape[0] * scale_percent / 100)
dim = (width, height)
# resize image
image1 = cv2.resize(image1, dim, interpolation=cv2.INTER_AREA)
# template matching
# Convert it to grayscale
img_gray = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
# Read the …Run Code Online (Sandbox Code Playgroud) python opencv image-processing computer-vision opencv-contrib
通过按下下面的按钮,我可以启用和禁用全屏模式,但在按下 f12 后,我无法禁用全屏模式。我参考了其他答案,他们只提供了一种检测窗口是否处于全屏模式的方法。我是无法获取用于从全屏(通过 f11 键制作)禁用全屏模式的代码。我尝试通过代码触发 f11 但它没有用。在所有浏览器中是否有任何解决方案?
Html code:
<button id="fullbutton" width="60px" height="60px" alt="logo" onclick="toggleFullScreen(this)">On</button>
Javascript code :
function toggleFullScreen(element) {
//first part
if((window.fullScreen) || (window.outerWidth === screen.width && window.outerHeight == screen.height)) {
console.log("full screen is enabled ")
if (document.exitFullscreen)
document.exitFullscreen();
else if (document.msExitFullscreen)
document.msExitFullscreen();
else if (document.mozCancelFullScreen)
document.mozCancelFullScreen();
else if (document.webkitExitFullscreen)
document.webkitExitFullscreen();
}else {
//second part
if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
if (document.documentElement.requestFullScreen) {
document.documentElement.requestFullScreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen(); //for mozilla
} else …Run Code Online (Sandbox Code Playgroud)