Skip to content

Commit 66c89ad

Browse files
committed
tweaking reflection detection algorithm again.
1 parent 985127e commit 66c89ad

File tree

5 files changed

+43
-27
lines changed

5 files changed

+43
-27
lines changed

relightlab/sphererow.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ void SphereRow::detectHighlights(bool update) {
147147
connect(detect_highlights, &DetectHighlights::progress, this, &SphereRow::updateStatus); //, Qt::QueuedConnection);
148148
}
149149
detect_highlights->stop();
150+
detect_highlights->update_positions = update;
150151

151152
ProcessQueue &queue = ProcessQueue::instance();
152153
queue.removeTask(detect_highlights);

relightlab/task.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ void Task::runScript(QString program, QString script, QStringList arguments, QSt
9393

9494
void Task::pause() {
9595
mutex.lock();
96-
assert(status == RUNNING);
9796
status = PAUSED;
9897
}
9998

@@ -106,7 +105,6 @@ void Task::resume() {
106105

107106
void Task::setStatus(Status s) {
108107
if(s == PAUSED) {
109-
assert(status != PAUSED);
110108
pause();
111109
return;
112110
}

relightlab/verifyview.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ VerifyView:: VerifyView(QImage &_image, int _height, QPointF &_pos, VerifyMarker
8080
center = QPointF(image.width()/2.0f, image.height()/2.0f);
8181

8282
marker_item = new VerifyMarker(this, marker);
83-
marker_item->radius = 8*scale;
83+
marker_item->radius = 8/scale;
8484
marker_item->setPos(pos + center);
8585
marker_item->active = !pos.isNull();
8686
scene.addItem(marker_item);
@@ -92,13 +92,23 @@ VerifyView:: VerifyView(QImage &_image, int _height, QPointF &_pos, VerifyMarker
9292
font.setPointSize(pix.height()/20.0f); // Set font size to 20
9393
img_number->setFont(font);
9494

95+
border = new QGraphicsRectItem(img_item->boundingRect(), img_item);
96+
border->setPen(QPen(Qt::transparent, 2.0*scale));
97+
9598
scene.addItem(img_number);
99+
100+
setSelected(true);
96101
}
97102

98103
void VerifyView::setImageNumber(int n) {
99104
img_number->setText(QString::number(n));
100105
}
101106

107+
void VerifyView::setSelected(bool isSelected) {
108+
selected = isSelected;
109+
border->setPen(isSelected ? QPen(Qt::blue, 2) : QPen(Qt::transparent));
110+
}
111+
102112
void VerifyView::update() {
103113
QPointF p = marker_item->pos();
104114
if(!img_item->boundingRect().contains(p)) {

relightlab/verifyview.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,27 @@ class VerifyView: public QGraphicsView {
3131
Q_OBJECT
3232
public:
3333
VerifyMarker::Marker marker;
34+
bool selected = false;
3435

3536
VerifyView(QImage &image, int height, QPointF &pos, VerifyMarker::Marker _marker, QWidget *parent = nullptr);
3637
void setImageNumber(int n);
3738
void update(); //update pos from marker
3839
void set(); //update marker from pos
40+
void setSelected(bool isSelected);
41+
42+
signals:
43+
void clicked(QMouseEvent *event);
3944

4045
protected:
4146
void resizeEvent(QResizeEvent *event) override;
4247
void keyPressEvent(QKeyEvent *event) override;
43-
protected:
48+
void mousePressEvent(QMouseEvent *event) override {
49+
emit clicked(event);
50+
}
4451
VerifyMarker *marker_item = nullptr;
4552
QGraphicsPixmapItem *img_item = nullptr;
4653
QGraphicsSimpleTextItem *img_number = nullptr;
54+
QGraphicsRectItem *border = nullptr;
4755
QGraphicsScene scene ;
4856
QImage ℑ
4957
QPointF center;

src/sphere.cpp

+22-23
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,17 @@ void Sphere::findHighlight(QImage img, int n, bool skip, bool update_positions)
208208
uchar threshold = 240;
209209
//0.5% of the area allocated to the reflection.
210210
int highlight_area = (inner.width()*inner.height())/200;
211+
if(n == 0)
212+
cout << "Area: " << highlight_area << endl;
211213
vector<int> histo;
212214

213215
//lower threshold until we find something.
216+
int max_luma_pixel = 0;
214217
QPointF bari(0, 0); //in image coords
215218
int count = 0;
216219
int iter = 0;
217220
while(count < highlight_area && threshold > 100) {
218-
bari = QPointF(0, 0);
221+
QPointF new_bari = QPointF(0, 0);
219222
count = 0;
220223
for(int y = inner.top(); y < inner.bottom(); y++) {
221224
for(int x = inner.left(); x < inner.right(); x++) {
@@ -237,38 +240,43 @@ void Sphere::findHighlight(QImage img, int n, bool skip, bool update_positions)
237240

238241
assert(X >= 0 && X < sphereImg.width());
239242
assert(Y >= 0 && Y < sphereImg.height());
240-
int mg = qGray(sphereImg.pixel(X, Y));
241-
if(g > mg) sphereImg.setPixel(X, Y, qRgb(g, g, g));
243+
int thumb_g = qGray(sphereImg.pixel(X, Y));
244+
if(g > thumb_g) sphereImg.setPixel(X, Y, qRgb(g, g, g));
242245

246+
max_luma_pixel = std::max(max_luma_pixel, g);
243247
if(g < threshold) continue;
244-
//sphereImg.setPixel(X, Y, qRgb(threshold, 0, 0));
245-
246-
bari += QPointF(x, y);
248+
249+
new_bari += QPointF(x, y);
247250
count++;
248251

249252
}
250253
}
251254
histo.push_back(count);
252255

253256
if(count > 0) {
254-
bari.rx() /= count;
255-
bari.ry() /= count;
257+
new_bari.rx() /= count;
258+
new_bari.ry() /= count;
259+
bari = new_bari;
256260
}
257-
//sphereImg.setPixel(int(bari.x()) - inner.left(), int(bari.y()) - inner.top(), qRgb(255, 255, 255));
258-
259-
261+
260262
threshold -= 10;
261263
iter++;
262264
}
265+
//threshold now is 10 lower so we get more points.
266+
threshold += 10;
267+
268+
if(bari.isNull()) {
269+
cout << "Bari null! " << n << endl;
270+
}
271+
263272
if(!update_positions)
264273
return;
265274

266-
//threshold now is 10 lower so we get more points.
267-
threshold += 10;
268275

269-
if(threshold < 127) {
276+
if(max_luma_pixel < 127) {
270277
//highlight in the mid greys? probably all the sphere is in shadow.
271278
lights[n] = QPointF(0, 0);
279+
cout << "Probably in shadow: " << n << endl;
272280
return;
273281
}
274282

@@ -306,16 +314,7 @@ void Sphere::findHighlight(QImage img, int n, bool skip, bool update_positions)
306314
bari = newbari/weight;
307315
radius *= 0.5;
308316
}
309-
//sphereImg.setPixel(int(bari.x()) - inner.left(), int(bari.y()) - inner.top(), qRgb(0, 255, 0));
310-
311317

312-
/* if(!sphere) {
313-
sphere = new QGraphicsPixmapItem(QPixmap::fromImage(sphereImg));
314-
sphere->setZValue(-0.5);
315-
sphere->setPos(inner.topLeft());
316-
} else {
317-
sphere->setPixmap(QPixmap::fromImage(sphereImg));
318-
} */
319318
lights[n] = bari;
320319
}
321320

0 commit comments

Comments
 (0)