NSImage* yourImage;
NSBitmapImageRep *bitmapRep = [NSBitmapImageRep imageRepWithData:[yourImage TIFFRepresentation]];
unsigned char* pixelData = [bitmapRep bitmapData];
ピクセルは、RGBフォーマットで、おそらくです:-)私にあなたの最高のショットを与えるC++とObjective-Cの両方が可能ですピクセルごとに。
あなたは、データ形式を確認できます。
int depth = [bitmapRep bitsPerSample];
int channels = [bitmapRep samplesPerPixel];
int height = [bitmapRep size].height;
int width = [bitmapRep size].width;
EDIT:私は少し(汚い&速い)テストプログラムを書いたWajihの主張を検証するために、私はとの国境を決定するために、いくつかの助けが必要私は、Wajihが特別なハフ変換(kht)実装(OpenCVバージョンではない)を指していることに気付きました。私はkhtの時間測定がありません。私は、jpg圧縮アーチファクトを処理するソースコードを更新しました。
std::string origFileName("../data/500396561_27052011171605_5877_3.jpg");
cv::Mat image = cv::imread(origFileName, 0);
std::cout << __PRETTY_FUNCTION__ << " -- widht, height = " << image.cols << ", " << image.rows << std::endl;
QElapsedTimer naiveTimer;
naiveTimer.start();
unsigned int x1 = 0;
unsigned int y1 = 0;
unsigned int x2 = 0;
unsigned int y2 = 0;
const unsigned int thresholdColor = 15; // how much may the color deviate
const unsigned int thresholdPixel = 5; // how many false detections do you want to tolerate
for (unsigned int ii = 0; ii < 1000; ++ii)
{
x1 = y1 = x2 = y2 = 0;
unsigned char* pixel = image.ptr<unsigned char>(0);
unsigned char border = *pixel;
bool top = true;
// horizontal border lines
for (int yy = 0; yy < image.rows; ++yy)
{
pixel = image.ptr<unsigned char>(yy);
int count = 0;
for (int xx = 0; xx < image.cols; ++xx)
{
if (255 - *pixel < thresholdColor)
++count;
++pixel;
}
if (image.cols - count < thresholdPixel)
{
if (top) ++y1;
else ++y2;
}
else top = false;
}
y2 = image.rows - y2;
// vertical border lines
bool left = true;
pixel = image.ptr<unsigned char>(0);
unsigned int offset = image.ptr<unsigned char>(1) - pixel;
for (int xx = 0; xx < image.cols; ++xx)
{
int count = 0;
unsigned char* colPixel = pixel++;
for (int yy = 0; yy < image.rows; ++yy)
{
if (255 - *colPixel < thresholdColor)
++count;
colPixel += offset;
}
if (image.rows - count < thresholdPixel)
{
if (left) ++x1;
else ++x2;
}
else left = false;
}
x2 = image.cols - x2;
}
std::cout << __PRETTY_FUNCTION__ << " -- Time elapsed: " << naiveTimer.elapsed() << std::endl;
std::cout << __PRETTY_FUNCTION__ << " -- x1 y1 x2 y2: " << x1 << " " << y1 << " " << x2 << " " << y2 << std::endl;
QImage original(origFileName.c_str());
QImage cropped = original.copy(x1, y1, x2 - x1, y2 - y1);
EHVhu.jpg(esbenrによって提供された画像以外にも、私はテストのために使う画像、):
画像はどのくらい変わっていますか?スキューなしで同じRGBの白の値が固定された画像を処理していますか? –
同じ白い色(ffffff og RGB:255,255,255)でパッディングされていますが、jpegは圧縮されているため、圧縮のために小さな微妙なニュアンスの変化があります。 – esbenr
好奇心の外に、あなたはこの問題に取り組んでいましたか? – bjoernz