我使用以下代码检测面部并在面部绘制矩形.
while True:
# get video frame
ret, img = cap.read()
input_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_h, img_w, _ = np.shape(input_img)
detected = detector(input_img, 1)
for i, d in enumerate(detected):
x1, y1, x2, y2, w, h = d.left(), d.top(), d.right() + 1, d.bottom() + 1, d.width(), d.height()
cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 0), 2)
cv2.imshow("result", img)
key = cv2.waitKey(30)
if key == 27:
break
Run Code Online (Sandbox Code Playgroud)
矩形看起来像这样:
但是我试图得到一个类似于这个的矩形:
是否有任何OpenCV或dlib函数可以帮助我获得这种有效的矩形?
我使用统一2018.3.5f1。我想在渲染图像时叠加自定义着色器。以下是我的onRenderImage函数。
void OnRenderImage(RenderTexture src, RenderTexture dest) {
// shaderMaterial renders the image with Barrel distortion and disparity effect
Graphics.Blit(camTextureHolder.mainTexture, nullRenderTexture, shaderMaterial);
// measure average frames per second
m_FpsAccumulator++;
if (Time.realtimeSinceStartup > m_FpsNextPeriod) {
m_CurrentFps = (int)(m_FpsAccumulator / fpsMeasurePeriod);
m_FpsAccumulator = 0;
m_FpsNextPeriod += fpsMeasurePeriod;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是在我尝试这样做时整个屏幕似乎都是黑色的。我可以知道如何解决此问题吗?
更新:
这是我正在使用的着色器的代码
Shader "Custom/FakeAR"
{
Properties{
_MainTex("", 2D) = "white" {}
[HideInInspector]_FOV("FOV", Range(1, 2)) = 1.6
[HideInInspector]_Disparity("Disparity", Range(0, 0.3)) = 0.1
[HideInInspector]_Alpha("Alpha", Range(0, 2.0)) = 1.0
}
SubShader{
Pass{
CGPROGRAM
#pragma vertex vert …Run Code Online (Sandbox Code Playgroud) 我试图训练实例分割模型.我使用以下代码生成tfrecord.
flags = tf.app.flags
flags.DEFINE_string('data_dir', '', 'Root directory to raw pet dataset.')
flags.DEFINE_string('output_dir', '', 'Path to directory to output TFRecords.')
flags.DEFINE_string('label_map_path', 'data/pet_label_map.pbtxt',
'Path to label map proto')
flags.DEFINE_boolean('faces_only', True, 'If True, generates bounding boxes '
'for pet faces. Otherwise generates bounding boxes (as '
'well as segmentations for full pet bodies). Note that '
'in the latter case, the resulting files are much larger.')
flags.DEFINE_string('mask_type', 'png', 'How to represent instance '
'segmentation masks. Options are "png" or "numerical".')
FLAGS = …Run Code Online (Sandbox Code Playgroud) 我使用以下代码在脸上画圆圈.
for (x, y, w, h) in faces:
cv2.circle(img, ( int((x + x + w )/2), int((y + y + h)/2 )), int (h / 2), (0, 255, 0), 5)
Run Code Online (Sandbox Code Playgroud)
但绘制圆的厚度完全是绿色.有没有办法让圆圈的百分之几(比方说30%)变成粉红色?