我在ScrollView中有一个TextView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parentLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/textAreaScroller"
android:layout_width="400px"
android:layout_height="200px"
android:layout_x="0px"
android:layout_y="25px"
android:fadeScrollbars="false"
android:scrollbarSize="3px"
android:scrollbarStyle="insideOverlay" >
<TextView
android:id="@+id/scrapbook"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="" />
</ScrollView>
<Button
android:id="@+id/upBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Up" />
<Button
android:id="@+id/downBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Down" />
<ImageView
android:id="@+id/imageView"
android:layout_width="400px"
android:layout_height="200px"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
TextView有很多文本,这就是可滚动的原因.我需要在TextView中将当前可见内容绘制到Bitmap.出于测试目的,我在ImageView中显示此位图.我有以下代码:
public class TextviewToImageActivity extends Activity {
private TextView textView;
private ScrollView textAreaScroller;
private ImageView imageView;
private Handler mHandler;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mHandler = new Handler();
imageView = (ImageView) findViewById(R.id.imageView); …Run Code Online (Sandbox Code Playgroud) 我有一个从某个角度拍摄的棋盘图像.现在我想扭曲视角,使棋盘图像再次看起来好像是从上面直接拍摄的.
我知道我可以尝试在匹配点之间使用'findHomography',但我想避免使用它,例如使用移动传感器的旋转数据来构建我自己的单应矩阵.我校准了相机以获得内在参数.然后让我们说下面的图像是围绕x轴以~60度角拍摄的.我认为我所要做的就是将相机矩阵与旋转矩阵相乘以获得单应矩阵.我尝试使用以下代码,但看起来我没有正确理解某些东西,因为它没有按预期工作(结果图像完全是黑色或白色.

import cv2
import numpy as np
import math
camera_matrix = np.array([[ 5.7415988502105745e+02, 0., 2.3986181527877352e+02],
[0., 5.7473682183375217e+02, 3.1723734404756237e+02],
[0., 0., 1.]])
distortion_coefficients = np.array([ 1.8662919398453856e-01, -7.9649812697463640e-01,
1.8178068172317731e-03, -2.4296638847737923e-03,
7.0519002388825025e-01 ])
theta = math.radians(60)
rotx = np.array([[1, 0, 0],
[0, math.cos(theta), -math.sin(theta)],
[0, math.sin(theta), math.cos(theta)]])
homography = np.dot(camera_matrix, rotx)
im = cv2.imread('data/chess1.jpg')
gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
im_warped = cv2.warpPerspective(gray, homography, (480, 640), flags=cv2.WARP_INVERSE_MAP)
cv2.imshow('image', im_warped)
cv2.waitKey()
pass
Run Code Online (Sandbox Code Playgroud)
校准后我也有失真系数.如何将这些结合到代码中以改善结果?
我有以下图片 
我试图找到主矩形的像素坐标(白线之间的像素坐标).我尝试了一些东西,但我无法获得足够好的解决方案.如果没有检测到所有矩形(特别是那些非常小的矩形),解决方案就不一定非常完美.虽然角落位置必须尽可能精确,特别是那些更大的模糊(我正在尝试编写一些简单的AR引擎).
我可以澄清只有4级灰度:0,110,180和255(打印时,没有屏幕会因闪电和阴影而变化)
到目前为止,我尝试了几件事:
看起来像将这两个想法结合起来会产生更好的结果.或者也许有人有不同的想法?
我也在考虑做洪水填充,但是很难找到确定好的种子点和阈值(背景中可能还有其他一些白色物体).此外,我希望稍后针对GPU进行优化,并且泛洪填充算法对此不太适合.
下面是我到目前为止尝试的一些示例代码:
image = cv2.imread('data/image.jpg');
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imshow('image', gray)
adaptive = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 601, 0)
cv2.imshow('adaptive', adaptive)
gradx = cv2.Sobel(gray, ddepth=cv2.CV_32F, dx=1, dy=0, ksize=3)
grady = cv2.Sobel(gray, ddepth=cv2.CV_32F, dx=0, dy=1, ksize=3)
abs_gradx = cv2.convertScaleAbs(grady)
abs_grady = cv2.convertScaleAbs(grady)
grad = cv2.addWeighted(abs_gradx, 0.5, abs_grady, 0.5, 0)
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(5,5))
grad = cv2.morphologyEx(grad, cv2.MORPH_OPEN, kernel)
grad = cv2.morphologyEx(grad, cv2.MORPH_CLOSE, kernel)
cv2.imshow('sobel',grad)
#kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(7,7))
#grad = cv2.morphologyEx(grad, cv2.MORPH_OPEN, kernel)
retval, …Run Code Online (Sandbox Code Playgroud) 我有我自己的 C++,我正在尝试使用 Pybind11 生成 python 绑定:
auto markerParams = MarkerDetector::Params::create(MarkerType::chessboard);
markerDetector.detect(image, markerParams);
Run Code Online (Sandbox Code Playgroud)
我有为MarkerDetector::Paramsstruct生成绑定的问题,因为它是一个内部结构,使用工厂方法构造,以 enum 作为参数:
enum MarkerType { chessboard, tag };
typedef std::vector<cv::Point> ContourType;
typedef std::vector<cv::Point2d> ContourTyped;
// contour full, contour approximate, area, corners
typedef std::tuple<ContourType, ContourType, double, ContourTyped> MarkerDescriptor;
class MarkerDetector {
public:
std::vector<MarkerDescriptor> detect(Mat image, const Params params);
struct Params {
int rows, cols;
ColorRange borderColor;
ShapeDetector::Params borderShape;
cv::Size borderSize;
cv::Size Size;
static Params create(MarkerType markerType) {
static Params markerTypes[] = {
{ 3, 6, ColorRange::GREEN, …Run Code Online (Sandbox Code Playgroud) 我检查了文档但是它不完整:没有提到rtype实际上是什么参数.
我认为它是一种减少类型,但我找不到任何变量cv2.CV_REDUCE_SUM等...我发现这个问题与许多使用不同变量名称的函数.在cv2 API中找到专有名称的最佳方法是什么?